Search in sources :

Example 6 with MigratableHandler

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));
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 7 with MigratableHandler

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);
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with MigratableHandler

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);
}
Also used : NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with MigratableHandler

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);
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 10 with MigratableHandler

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;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Aggregations

MigratableHandler (com.hazelcast.internal.networking.nonblocking.MigratableHandler)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 NonBlockingIOThread (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)5 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 IMap (com.hazelcast.core.IMap)1 TcpIpConnection (com.hazelcast.nio.tcp.TcpIpConnection)1 TcpIpConnectionManager (com.hazelcast.nio.tcp.TcpIpConnectionManager)1 Map (java.util.Map)1