Search in sources :

Example 51 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class ClusterServiceMemberListTest method verifyMembersFromDataMember.

private void verifyMembersFromDataMember(final HazelcastInstance instance) {
    final Member localMember = getLocalMember(instance);
    final ClusterService clusterService = getClusterService(instance);
    final Collection<Member> liteMembers = clusterService.getMembers(LITE_MEMBER_SELECTOR);
    final Collection<Member> dataMembers = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    assertContains(dataMembers, localMember);
    assertNotContains(liteMembers, localMember);
    final Collection<Member> dataMembersWithoutThis = clusterService.getMembers(MemberSelectors.and(DATA_MEMBER_SELECTOR, NON_LOCAL_MEMBER_SELECTOR));
    assertNotContains(dataMembersWithoutThis, localMember);
    final Collection<Member> liteMembersWithThis = clusterService.getMembers(MemberSelectors.or(LITE_MEMBER_SELECTOR, LOCAL_MEMBER_SELECTOR));
    assertContains(liteMembersWithThis, localMember);
}
Also used : Accessors.getClusterService(com.hazelcast.test.Accessors.getClusterService) ClusterService(com.hazelcast.internal.cluster.ClusterService)

Example 52 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class SplitBrainTest method when_minorityMasterBecomesMajorityMaster_then_jobKeepsRunning.

@Test
public void when_minorityMasterBecomesMajorityMaster_then_jobKeepsRunning() {
    int firstSubClusterSize = 2;
    int secondSubClusterSize = 1;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    NoOutputSourceP.executionStarted = new CountDownLatch(secondSubClusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = instances[2].getJet().newJob(dag);
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertEquals(clusterSize, instances.length);
        logger.info("Shutting down 1st instance");
        instances[0].shutdown();
        logger.info("1st instance down, starting another instance");
        createHazelcastInstance(createConfig());
        logger.info("Shutting down 2nd instance");
        instances[1].shutdown();
        assertTrue(((ClusterService) instances[2].getCluster()).isMaster());
        assertJobStatusEventually(jobRef[0], RUNNING, 10);
        assertTrueAllTheTime(() -> assertEquals(RUNNING, jobRef[0].getStatus()), 5);
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, null, afterMerge);
}
Also used : MasterContext(com.hazelcast.jet.impl.MasterContext) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClusterService(com.hazelcast.internal.cluster.ClusterService) Future(java.util.concurrent.Future) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) BiConsumer(java.util.function.BiConsumer) Assert.fail(org.junit.Assert.fail) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NightlyTest(com.hazelcast.test.annotation.NightlyTest) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) ClusterService(com.hazelcast.internal.cluster.ClusterService) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 53 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class FlakeIdGeneratorProxyTest method initialize.

public void initialize(FlakeIdGeneratorConfig config) {
    ILogger logger = mock(ILogger.class);
    clusterService = mock(ClusterService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    FlakeIdGeneratorService service = mock(FlakeIdGeneratorService.class);
    when(nodeEngine.getLogger(FlakeIdGeneratorProxy.class)).thenReturn(logger);
    when(nodeEngine.isRunning()).thenReturn(true);
    config.setName("foo");
    when(nodeEngine.getConfig()).thenReturn(new Config().addFlakeIdGeneratorConfig(config));
    when(nodeEngine.getClusterService()).thenReturn(clusterService);
    Address address = null;
    try {
        address = new Address("127.0.0.1", 5701);
    } catch (UnknownHostException e) {
    // no-op
    }
    when(nodeEngine.getLocalMember()).thenReturn(new MemberImpl(address, MemberVersion.UNKNOWN, true, UUID.randomUUID()));
    UUID source = nodeEngine.getLocalMember().getUuid();
    gen = new FlakeIdGeneratorProxy("foo", nodeEngine, service, source);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.cluster.Address) UnknownHostException(java.net.UnknownHostException) Config(com.hazelcast.config.Config) FlakeIdGeneratorConfig(com.hazelcast.config.FlakeIdGeneratorConfig) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ILogger(com.hazelcast.logging.ILogger) UUID(java.util.UUID)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)53 Address (com.hazelcast.cluster.Address)11 Member (com.hazelcast.cluster.Member)10 ArrayList (java.util.ArrayList)10 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)8 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)8 Future (java.util.concurrent.Future)8 UUID (java.util.UUID)6 CPMember (com.hazelcast.cp.CPMember)5 ILogger (com.hazelcast.logging.ILogger)5 Accessors.getClusterService (com.hazelcast.test.Accessors.getClusterService)5 ClusterState (com.hazelcast.cluster.ClusterState)4 Node (com.hazelcast.instance.impl.Node)4 JsonObject (com.hazelcast.internal.json.JsonObject)4 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 Member (com.hazelcast.core.Member)3 CPGroupId (com.hazelcast.cp.CPGroupId)3 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)3