Java Code Examples for com.hazelcast.client.HazelcastClient#shutdownAll()

The following examples show how to use com.hazelcast.client.HazelcastClient#shutdownAll() . 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: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_simple_sequencer_initialization()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 2
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_single_id_generation()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
        assertNotNull(sequencer.next());
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 3
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test(expected = SnowcastStateException.class)
public void test_id_generation_in_detached_state()
        throws Exception {

    Hazelcast.newHazelcastInstance();
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
        assertNotNull(sequencer.next());

        // Detach the node and free the currently used logical node ID
        sequencer.detachLogicalNode();

        sequencer.next();
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 4
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test(expected = SnowcastStateException.class)
public void test_id_generation_in_attach_wrong_state()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);

        sequencer.attachLogicalNode();
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 5
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_sequencer_counter_value()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence = generateSequenceId(10000, 10, 100, shifting);

        assertEquals(100, sequencer.counterValue(sequence));
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 6
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_sequencer_timestamp()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence = generateSequenceId(10000, 10, 100, shifting);

        assertEquals(10000, sequencer.timestampValue(sequence));
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 7
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_sequencer_logical_node_id()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence = generateSequenceId(10000, 10, 100, shifting);

        assertEquals(10, sequencer.logicalNodeId(sequence));
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 8
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 5 votes vote down vote up
@Test(expected = SnowcastStateException.class)
public void test_destroyed_state()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
        assertNotNull(sequencer.next());

        snowcast.destroySequencer(sequencer);

        long deadline = System.currentTimeMillis() + 60000;
        while (true) {
            // Will eventually fail
            sequencer.next();

            if (System.currentTimeMillis() >= deadline) {
                // Safe exit after another minute of waiting for the event
                return;
            }
        }

    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 9
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 5 votes vote down vote up
@Test(expected = SnowcastStateException.class)
public void test_destroyed_state_from_node()
        throws Exception {

    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        SnowcastEpoch epoch = buildEpoch();

        Snowcast snowcastClient = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencerClient = buildSnowcastSequencer(snowcastClient, epoch);

        assertNotNull(sequencerClient);
        assertNotNull(sequencerClient.next());

        Snowcast snowcastNode = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencerNode = buildSnowcastSequencer(snowcastNode, epoch);

        assertNotNull(sequencerNode);
        assertNotNull(sequencerNode.next());

        snowcastNode.destroySequencer(sequencerNode);

        long deadline = System.currentTimeMillis() + 60000;
        while (true) {
            // Will eventually fail
            sequencerClient.next();

            if (System.currentTimeMillis() >= deadline) {
                // Safe exit after another minute of waiting for the event
                return;
            }
        }

    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 10
Source File: ClientBasicTestCase.java    From snowcast with Apache License 2.0 5 votes vote down vote up
@Test
public void test_id_generation_in_reattached_state()
        throws Exception {

    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(client);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
        assertNotNull(sequencer.next());

        // Detach the node and free the currently used logical node ID
        sequencer.detachLogicalNode();

        try {
            // Must fail since we're in detached state!
            sequencer.next();
            fail();
        } catch (SnowcastStateException e) {
            // Expected, so ignore
        }

        // Re-attach the node and assign a free logical node ID
        sequencer.attachLogicalNode();

        assertNotNull(sequencer.next());
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
 
Example 11
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();
    }
}
 
Example 12
Source File: KeyUtilsTest.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() {
    HazelcastClient.shutdownAll();
    Hazelcast.shutdownAll();
}