use of java.util.concurrent.ConcurrentHashMap in project storm by apache.
the class PacemakerTest method testServerDeletePulseId.
@Test
public void testServerDeletePulseId() {
Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
makeNode(handler, "/some-root/DELETE_PULSE_ID/foo");
makeNode(handler, "/some-root/DELETE_PULSE_ID/bar");
makeNode(handler, "/some-root/DELETE_PULSE_ID/baz");
makeNode(handler, "/some-root/DELETE_PULSE_ID/boo");
messageWithRandId(HBServerMessageType.DELETE_PULSE_ID, HBMessageData.path("/some-root/DELETE_PULSE_ID/foo"));
HBMessage response = handler.handleMessage(hbMessage, true);
Assert.assertEquals(mid, response.get_message_id());
Assert.assertEquals(HBServerMessageType.DELETE_PULSE_ID_RESPONSE, response.get_type());
Assert.assertNull(response.get_data());
messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root/DELETE_PULSE_ID"));
response = handler.handleMessage(hbMessage, true);
List<String> pulseIds = response.get_data().get_nodes().get_pulseIds();
Assert.assertEquals(mid, response.get_message_id());
Assert.assertEquals(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, response.get_type());
Assert.assertFalse(pulseIds.contains("foo"));
}
use of java.util.concurrent.ConcurrentHashMap in project storm by apache.
the class PacemakerTest method testServerCreatePath.
@Test
public void testServerCreatePath() {
Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
messageWithRandId(HBServerMessageType.CREATE_PATH, HBMessageData.path("/testpath"));
HBMessage response = handler.handleMessage(hbMessage, true);
Assert.assertEquals(mid, response.get_message_id());
Assert.assertEquals(HBServerMessageType.CREATE_PATH_RESPONSE, response.get_type());
Assert.assertNull(response.get_data());
}
use of java.util.concurrent.ConcurrentHashMap in project zookeeper by apache.
the class ExpiryQueue method update.
/**
* Adds or updates expiration time for element in queue, rounding the
* timeout to the expiry interval bucketed used by this queue.
* @param elem element to add/update
* @param timeout timout in milliseconds
* @return time at which the element is now set to expire if
* changed, or null if unchanged
*/
public Long update(E elem, int timeout) {
Long prevExpiryTime = elemMap.get(elem);
long now = Time.currentElapsedTime();
Long newExpiryTime = roundToNextInterval(now + timeout);
if (newExpiryTime.equals(prevExpiryTime)) {
// No change, so nothing to update
return null;
}
// First add the elem to the new expiry time bucket in expiryMap.
Set<E> set = expiryMap.get(newExpiryTime);
if (set == null) {
// Construct a ConcurrentHashSet using a ConcurrentHashMap
set = Collections.newSetFromMap(new ConcurrentHashMap<E, Boolean>());
// Put the new set in the map, but only if another thread
// hasn't beaten us to it
Set<E> existingSet = expiryMap.putIfAbsent(newExpiryTime, set);
if (existingSet != null) {
set = existingSet;
}
}
set.add(elem);
// Map the elem to the new expiry time. If a different previous
// mapping was present, clean up the previous expiry bucket.
prevExpiryTime = elemMap.put(elem, newExpiryTime);
if (prevExpiryTime != null && !newExpiryTime.equals(prevExpiryTime)) {
Set<E> prevSet = expiryMap.get(prevExpiryTime);
if (prevSet != null) {
prevSet.remove(elem);
}
}
return newExpiryTime;
}
use of java.util.concurrent.ConcurrentHashMap in project zookeeper by apache.
the class FLETest method runElection.
/**
* Test leader election for a number of rounds. In all rounds but the last one
* we kill the leader.
*
* @param rounds
* @throws Exception
*/
private void runElection(int rounds) throws Exception {
ConcurrentHashMap<Long, HashSet<Integer>> quora = new ConcurrentHashMap<Long, HashSet<Integer>>();
LOG.info("TestLE: " + getTestName() + ", " + count);
/*
* Creates list of peers.
*/
for (int i = 0; i < count; i++) {
port[i] = PortAssignment.unique();
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", port[i])));
tmpdir[i] = ClientBase.createTmpDir();
}
/*
* Start one LEThread for each peer we want to run.
*/
for (int i = 0; i < count; i++) {
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
peer.startLeaderElection();
LEThread thread = new LEThread(this, peer, i, rounds, quora);
thread.start();
threads.add(thread);
}
LOG.info("Started threads " + getTestName());
int waitCounter = 0;
synchronized (this) {
while (((successCount <= count / 2) || (leader == -1)) && (waitCounter < MAX_LOOP_COUNTER)) {
this.wait(200);
waitCounter++;
}
}
LOG.info("Success count: " + successCount);
/*
* Lists what threads haven't joined. A thread doesn't join if
* it hasn't decided upon a leader yet. It can happen that a
* peer is slow or disconnected, and it can take longer to
* nominate and connect to the current leader.
*/
for (int i = 0; i < threads.size(); i++) {
if (threads.get(i).isAlive()) {
LOG.info("Threads didn't join: " + i);
}
}
/*
* If we have a majority, then we are good to go.
*/
if (successCount <= count / 2) {
Assert.fail("Fewer than a a majority has joined");
}
/*
* I'm done so joining.
*/
if (!joinedThreads.contains(leader)) {
Assert.fail("Leader hasn't joined: " + leader);
}
}
use of java.util.concurrent.ConcurrentHashMap in project crate by crate.
the class ApplySettingsTest method testOnRefreshSettings.
@Test
public void testOnRefreshSettings() throws Exception {
ConcurrentHashMap<String, Object> values = new ConcurrentHashMap<>();
ClusterSettingsExpression.ApplySettings applySettings = new ClusterSettingsExpression.ApplySettings(Settings.EMPTY, values);
Settings.Builder builder = Settings.builder().put(CrateSettings.STATS_JOBS_LOG_SIZE.settingName(), 1).put(CrateSettings.STATS_ENABLED.settingName(), false).put(CrateSettings.GRACEFUL_STOP_MIN_AVAILABILITY.settingName(), "full").put(CrateSettings.GRACEFUL_STOP_TIMEOUT.settingName(), "1m").put(CrateSettings.DISCOVERY_ZEN_MIN_MASTER_NODES.settingName(), 2);
Settings settings = builder.build();
applySettings.onRefreshSettings(settings);
String name = CrateSettings.STATS_JOBS_LOG_SIZE.settingName();
assertEquals(values.get(name), settings.getAsInt(name, 0));
name = CrateSettings.STATS_ENABLED.settingName();
assertEquals(values.get(name), settings.getAsBoolean(name, true));
name = CrateSettings.GRACEFUL_STOP_MIN_AVAILABILITY.settingName();
assertEquals(values.get(name), settings.get(name, "none"));
name = CrateSettings.GRACEFUL_STOP_TIMEOUT.settingName();
assertEquals(values.get(name), settings.get(name, "1h"));
name = CrateSettings.DISCOVERY_ZEN_MIN_MASTER_NODES.settingName();
assertEquals(values.get(name), settings.getAsInt(name, 2));
}
Aggregations