use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class MonkeyMigrationStrategyTest method assertFairSelection.
private void assertFairSelection(int iterationCount, double toleranceFactor, MigratableHandler handler1, MigratableHandler handler2) {
int handler1Count = 0;
int handler2Count = 0;
for (int i = 0; i < iterationCount; i++) {
MigratableHandler candidate = strategy.findHandlerToMigrate(imbalance);
if (candidate == handler1) {
handler1Count++;
} else if (candidate == handler2) {
handler2Count++;
} else {
fail("No handler selected");
}
}
int diff = abs(handler1Count - handler2Count);
assertTrue(diff < (iterationCount * toleranceFactor));
}
use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class MonkeyMigrationStrategyTest method imbalanceDetected_shouldReturnTrueWhenHandlerExist.
@Test
public void imbalanceDetected_shouldReturnTrueWhenHandlerExist() {
MigratableHandler handler = mock(MigratableHandler.class);
selectorToHandlers.put(imbalance.sourceSelector, setOf(handler));
boolean imbalanceDetected = strategy.imbalanceDetected(imbalance);
assertTrue(imbalanceDetected);
}
use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class EventCountBasicMigrationStrategyTest method testFindHandlerToMigrate.
@Test
public void testFindHandlerToMigrate() throws Exception {
NonBlockingIOThread sourceSelector = mock(NonBlockingIOThread.class);
NonBlockingIOThread destinationSelector = mock(NonBlockingIOThread.class);
imbalance.sourceSelector = sourceSelector;
imbalance.destinationSelector = destinationSelector;
imbalance.minimumEvents = 100;
MigratableHandler handler1 = mock(MigratableHandler.class);
handlerEventsCounter.set(handler1, 100l);
selectorToHandlers.put(destinationSelector, singleton(handler1));
imbalance.maximumEvents = 300;
MigratableHandler handler2 = mock(MigratableHandler.class);
MigratableHandler handler3 = mock(MigratableHandler.class);
handlerEventsCounter.set(handler2, 200l);
handlerEventsCounter.set(handler3, 100l);
selectorToHandlers.put(sourceSelector, setOf(handler2, handler3));
MigratableHandler handlerToMigrate = strategy.findHandlerToMigrate(imbalance);
assertEquals(handler3, handlerToMigrate);
}
use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class IOBalancerStressTest method assertBalanced.
/**
* A selector is balanced if:
* - it has 1 active handler (so a high event count)
* - potentially 1 dead handler (duplicate connection). So event count should be low.
*
* @param selector
* @param handlers
*/
public void assertBalanced(NonBlockingIOThread selector, Set<MigratableHandler> handlers) {
assertTrue("no handlers were found for selector:" + selector, handlers.size() > 0);
assertTrue("too many handlers were found for selector:" + selector, handlers.size() <= 2);
Iterator<MigratableHandler> iterator = handlers.iterator();
MigratableHandler activeHandler = iterator.next();
if (handlers.size() == 2) {
MigratableHandler deadHandler = iterator.next();
if (activeHandler.getEventCount() < deadHandler.getEventCount()) {
MigratableHandler tmp = deadHandler;
deadHandler = activeHandler;
activeHandler = tmp;
}
// the maximum number of events seen on the dead connection is 3. 10 should be save to assume the
// connection is dead.
assertTrue("at most 10 event should have been received, number of events received:" + deadHandler.getEventCount(), deadHandler.getEventCount() < 10);
}
assertTrue("activeHandlerEvent count should be at least 1000, but was:" + activeHandler.getEventCount(), activeHandler.getEventCount() > 1000);
}
use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class IOBalancerStressTest method assertBalanced.
private void assertBalanced(HazelcastInstance hz) {
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(hz);
Map<NonBlockingIOThread, Set<MigratableHandler>> handlersPerSelector = getHandlersPerSelector(connectionManager);
try {
for (Map.Entry<NonBlockingIOThread, Set<MigratableHandler>> entry : handlersPerSelector.entrySet()) {
NonBlockingIOThread selector = entry.getKey();
Set<MigratableHandler> handlers = entry.getValue();
assertBalanced(selector, handlers);
}
} catch (AssertionError e) {
// if something fails, we want to see the debug
System.out.println(debug(connectionManager));
throw e;
}
}
Aggregations