Search in sources :

Example 6 with ClusterDiscoveryService

use of com.hazelcast.client.impl.clientside.ClusterDiscoveryService in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method test_continueFromWhereItleftOff.

@Test
public void test_continueFromWhereItleftOff() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int numberOfCandidates = 10;
    for (int i = 0; i < numberOfCandidates; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 1, lifecycleService);
    getNextCluster(discoveryService);
    assertEquals(arrayList.get(2), getNextCluster(discoveryService));
    assertEquals(arrayList.get(3), getNextCluster(discoveryService));
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with ClusterDiscoveryService

use of com.hazelcast.client.impl.clientside.ClusterDiscoveryService in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method test_no_iteration_when_try_count_is_zero.

@Test
public void test_no_iteration_when_try_count_is_zero() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int numberOfCandidates = 10;
    for (int i = 0; i < numberOfCandidates; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 0, lifecycleService);
    MutableInteger count = new MutableInteger();
    for (int i = 0; i < 3; i++) {
        discoveryService.tryNextCluster((o, o2) -> {
            count.value++;
            return false;
        });
    }
    assertEquals(0, count.value);
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) MutableInteger(com.hazelcast.internal.util.MutableInteger) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ClusterDiscoveryService

use of com.hazelcast.client.impl.clientside.ClusterDiscoveryService in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method testSingleCandidateBehavior.

@Test
public void testSingleCandidateBehavior() {
    CandidateClusterContext context = createContext(1);
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    arrayList.add(context);
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 1, lifecycleService);
    assertNotNull(discoveryService.current());
    for (int i = 1; i < 3; i++) {
        assertNotNull(discoveryService.current());
        assertEquals(context, getNextCluster(discoveryService));
    }
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with ClusterDiscoveryService

use of com.hazelcast.client.impl.clientside.ClusterDiscoveryService in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method test_oneIteration.

@Test
public void test_oneIteration() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int numberOfCandidates = 10;
    for (int i = 0; i < numberOfCandidates; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 1, lifecycleService);
    MutableInteger count = new MutableInteger();
    discoveryService.tryNextCluster((o, o2) -> {
        count.value++;
        return false;
    });
    assertEquals(numberOfCandidates, count.value);
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) MutableInteger(com.hazelcast.internal.util.MutableInteger) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CandidateClusterContext (com.hazelcast.client.impl.clientside.CandidateClusterContext)9 ClusterDiscoveryService (com.hazelcast.client.impl.clientside.ClusterDiscoveryService)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 MutableInteger (com.hazelcast.internal.util.MutableInteger)3 HashSet (java.util.HashSet)3