com.hazelcast.core.PartitionService Java Examples

The following examples show how to use com.hazelcast.core.PartitionService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Hazelcast3Driver.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
public static void warmupPartitions(HazelcastInstance hazelcastInstance) {
    LOGGER.info("Waiting for partition warmup");

    PartitionService partitionService = hazelcastInstance.getPartitionService();
    long started = System.nanoTime();
    for (Partition partition : partitionService.getPartitions()) {
        if (System.nanoTime() - started > PARTITION_WARMUP_TIMEOUT_NANOS) {
            throw new IllegalStateException("Partition warmup timeout. Partitions didn't get an owner in time");
        }

        while (partition.getOwner() == null) {
            LOGGER.debug("Partition owner is not yet set for partitionId: " + partition.getPartitionId());
            sleepMillisThrowException(PARTITION_WARMUP_SLEEP_INTERVAL_MILLIS);
        }
    }

    LOGGER.info("Partitions are warmed up successfully");
}
 
Example #2
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public PartitionService getPartitionService() {
    return null;
}
 
Example #3
Source File: SequencerBackupTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_simple_backup_create_sequencer_definition_owner() {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance();

    try {
        final String sequencerName = generateKeyOwnedBy(hazelcastInstance1);

        // Build the custom epoch
        SnowcastEpoch epoch = buildEpoch();

        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);

        InternalSequencer sequencer1 = (InternalSequencer) buildSnowcastSequencer(snowcast1, sequencerName, epoch);
        InternalSequencer sequencer2 = (InternalSequencer) buildSnowcastSequencer(snowcast2, sequencerName, epoch);

        NodeSequencerService sequencerService1 = (NodeSequencerService) sequencer1.getSequencerService();
        NodeSequencerService sequencerService2 = (NodeSequencerService) sequencer2.getSequencerService();

        PartitionService partitionService = hazelcastInstance1.getPartitionService();
        int partitionId = partitionService.getPartition(sequencerName).getPartitionId();

        final SequencerPartition partition1 = sequencerService1.getSequencerPartition(partitionId);
        final SequencerPartition partition2 = sequencerService2.getSequencerPartition(partitionId);

        assertTrueEventually(new AssertTask() {
            @Override
            public void run()
                    throws Exception {

                SequencerDefinition sequencerDefinition1 = partition1.getSequencerDefinition(sequencerName);
                SequencerDefinition sequencerDefinition2 = partition2.getSequencerDefinition(sequencerName);

                assertEquals(sequencerDefinition1, sequencerDefinition2);
            }
        });
    } finally {
        factory.shutdownAll();
    }
}
 
Example #4
Source File: SequencerBackupTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_simple_backup_create_sequencer_definition_non_owner() {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance();

    try {
        final String sequencerName = generateKeyOwnedBy(hazelcastInstance1);

        // Build the custom epoch
        SnowcastEpoch epoch = buildEpoch();

        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);

        InternalSequencer sequencer2 = (InternalSequencer) buildSnowcastSequencer(snowcast2, sequencerName, epoch);
        InternalSequencer sequencer1 = (InternalSequencer) buildSnowcastSequencer(snowcast1, sequencerName, epoch);

        NodeSequencerService sequencerService1 = (NodeSequencerService) sequencer1.getSequencerService();
        NodeSequencerService sequencerService2 = (NodeSequencerService) sequencer2.getSequencerService();

        PartitionService partitionService = hazelcastInstance1.getPartitionService();
        int partitionId = partitionService.getPartition(sequencerName).getPartitionId();

        final SequencerPartition partition1 = sequencerService1.getSequencerPartition(partitionId);
        final SequencerPartition partition2 = sequencerService2.getSequencerPartition(partitionId);

        assertTrueEventually(new AssertTask() {
            @Override
            public void run()
                    throws Exception {

                SequencerDefinition sequencerDefinition1 = partition1.getSequencerDefinition(sequencerName);
                SequencerDefinition sequencerDefinition2 = partition2.getSequencerDefinition(sequencerName);

                assertEquals(sequencerDefinition1, sequencerDefinition2);
            }
        });
    } finally {
        factory.shutdownAll();
    }
}
 
Example #5
Source File: ClientSequencerBackupTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_simple_backup_create_sequencer_definition_client() {
    HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config1);
    HazelcastInstance hazelcastInstance2 = Hazelcast.newHazelcastInstance(config2);

    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        final String sequencerName = generateKeyOwnedBy(hazelcastInstance1);

        // Build the custom epoch
        SnowcastEpoch epoch = buildEpoch();

        Snowcast clientSnowcast = SnowcastSystem.snowcast(client);
        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);

        buildSnowcastSequencer(clientSnowcast, sequencerName, epoch);

        InternalSequencer sequencer1 = (InternalSequencer) buildSnowcastSequencer(snowcast1, sequencerName, epoch);
        InternalSequencer sequencer2 = (InternalSequencer) buildSnowcastSequencer(snowcast2, sequencerName, epoch);

        NodeSequencerService sequencerService1 = (NodeSequencerService) sequencer1.getSequencerService();
        NodeSequencerService sequencerService2 = (NodeSequencerService) sequencer2.getSequencerService();

        PartitionService partitionService = hazelcastInstance1.getPartitionService();
        int partitionId = partitionService.getPartition(sequencerName).getPartitionId();

        final SequencerPartition partition1 = sequencerService1.getSequencerPartition(partitionId);
        final SequencerPartition partition2 = sequencerService2.getSequencerPartition(partitionId);

        assertTrueEventually(new AssertTask() {
            @Override
            public void run()
                    throws Exception {

                SequencerDefinition sequencerDefinition1 = partition1.getSequencerDefinition(sequencerName);
                SequencerDefinition sequencerDefinition2 = partition2.getSequencerDefinition(sequencerName);

                assertEquals(sequencerDefinition1, sequencerDefinition2);
            }
        });
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}