Search in sources :

Example 1 with ClusterDiscoveryService

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

the class ClientClusterDiscoveryServiceTest method test_current_and_next_clusters_are_same_when_single_candidate_with_multiple_tries.

@Test
public void test_current_and_next_clusters_are_same_when_single_candidate_with_multiple_tries() {
    CandidateClusterContext context = createContext(1);
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    arrayList.add(context);
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 7, lifecycleService);
    Set<CandidateClusterContext> scannedClusters = new HashSet<>();
    discoveryService.tryNextCluster((current, next) -> {
        scannedClusters.add(current);
        scannedClusters.add(next);
        return false;
    });
    assertEquals(1, scannedClusters.size());
    assertTrue(scannedClusters.contains(context));
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ClusterDiscoveryService

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

the class ClientClusterDiscoveryServiceTest method test_n_iterations.

@Test
public void test_n_iterations() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int n = 15;
    for (int i = 0; i < 10; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, n, lifecycleService);
    MutableInteger count = new MutableInteger();
    discoveryService.tryNextCluster((o, o2) -> {
        count.value++;
        return false;
    });
    assertEquals(10 * n, 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 3 with ClusterDiscoveryService

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

the class ClientClusterDiscoveryServiceTest method test_current_candidate_does_not_change_when_try_count_is_zero.

@Test
public void test_current_candidate_does_not_change_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);
    Set<CandidateClusterContext> candidates = new HashSet<>();
    for (int i = 0; i < 3; i++) {
        candidates.add(discoveryService.current());
    }
    assertTrue(candidates.toString(), candidates.contains(arrayList.get(0)));
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ClusterDiscoveryService

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

the class ClientClusterDiscoveryServiceTest method testCurrentAndNextReturnsCorrect.

@Test
public void testCurrentAndNextReturnsCorrect() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    CandidateClusterContext first = createContext(1);
    arrayList.add(first);
    CandidateClusterContext second = createContext(2);
    arrayList.add(second);
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 10, lifecycleService);
    assertEquals(first, discoveryService.current());
    assertEquals(second, getNextCluster(discoveryService));
    assertEquals(second, discoveryService.current());
    assertEquals(first, getNextCluster(discoveryService));
    assertEquals(first, discoveryService.current());
}
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 5 with ClusterDiscoveryService

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

the class ClientClusterDiscoveryServiceTest method test_current_and_next_clusters_are_same_when_single_candidate.

@Test
public void test_current_and_next_clusters_are_same_when_single_candidate() {
    CandidateClusterContext context = createContext(1);
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    arrayList.add(context);
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 1, lifecycleService);
    Set<CandidateClusterContext> scannedClusters = new HashSet<>();
    discoveryService.tryNextCluster((current, next) -> {
        scannedClusters.add(current);
        scannedClusters.add(next);
        return false;
    });
    assertEquals(1, scannedClusters.size());
    assertTrue(scannedClusters.contains(context));
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) HashSet(java.util.HashSet) 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