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;
}
}
use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.
the class LoadTrackerTest method testUpdateImbalance_notUsingSingleHandlerSelectorAsSource.
// there is no point in selecting a selector with a single handler as source.
@Test
public void testUpdateImbalance_notUsingSingleHandlerSelectorAsSource() throws Exception {
MigratableHandler selector1Handler1 = mock(MigratableHandler.class);
// the first selector has a handler with a large number of events
when(selector1Handler1.getEventCount()).thenReturn(10000l);
when(selector1Handler1.getOwner()).thenReturn(selector1);
loadTracker.addHandler(selector1Handler1);
MigratableHandler selector2Handler = mock(MigratableHandler.class);
when(selector2Handler.getEventCount()).thenReturn(200l);
when(selector2Handler.getOwner()).thenReturn(selector2);
loadTracker.addHandler(selector2Handler);
MigratableHandler selector2Handler2 = mock(MigratableHandler.class);
when(selector2Handler2.getEventCount()).thenReturn(200l);
when(selector2Handler2.getOwner()).thenReturn(selector2);
loadTracker.addHandler(selector2Handler2);
LoadImbalance loadImbalance = loadTracker.updateImbalance();
assertEquals(400, loadImbalance.minimumEvents);
assertEquals(400, loadImbalance.maximumEvents);
assertEquals(selector2, loadImbalance.destinationSelector);
assertEquals(selector2, loadImbalance.sourceSelector);
}
Aggregations