Java Code Examples for com.hazelcast.test.TestHazelcastInstanceFactory#newHazelcastInstance()

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

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencerFromCalendar(snowcast);

        assertNotNull(sequencer);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 2
Source File: MultiNodeTestCase.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 {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    factory.newHazelcastInstance();

    try {
        String sequencerName = generateKeyNotOwnedBy(hazelcastInstance);
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast, sequencerName);

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

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

        sequencer.next();
    } finally {
        factory.shutdownAll();
    }
}
 
Example 3
Source File: MultiNodeTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_simple_sequencer_initialization()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    factory.newHazelcastInstance();

    try {
        String sequencerName = generateKeyNotOwnedBy(hazelcastInstance);
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast, sequencerName);

        assertNotNull(sequencer);

        // Request the current state of the sequencer
        SnowcastSequenceState state = sequencer.getSequencerState();

        // Destroy the sequencer, cluster-wide operation
        snowcast.destroySequencer(sequencer);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 4
Source File: SnowcastSequenceUtilsTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_comparator_equal()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(SnowcastConstants.DEFAULT_MAX_LOGICAL_NODES_13_BITS);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence1 = generateSequenceId(10000, 1, 1, shifting);
        long sequence2 = generateSequenceId(10000, 2, 1, shifting);

        Comparator<Long> comparator = SnowcastSequenceUtils.snowcastSequenceComparator(sequencer);

        assertEquals(0, comparator.compare(sequence1, sequence2));
    } finally {
        factory.shutdownAll();
    }
}
 
Example 5
Source File: SnowcastSequenceUtilsTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_comparator_first_lower_by_timestamp()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(SnowcastConstants.DEFAULT_MAX_LOGICAL_NODES_13_BITS);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence1 = generateSequenceId(10000, 1, 1, shifting);
        long sequence2 = generateSequenceId(10001, 1, 1, shifting);

        Comparator<Long> comparator = SnowcastSequenceUtils.snowcastSequenceComparator(sequencer);

        assertEquals(-1, comparator.compare(sequence1, sequence2));
    } finally {
        factory.shutdownAll();
    }
}
 
Example 6
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_sequencer_logical_node_id()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        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 {
        factory.shutdownAll();
    }
}
 
Example 7
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_sequencer_counter_value()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        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 {
        factory.shutdownAll();
    }
}
 
Example 8
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test(expected = SnowcastSequencerAlreadyRegisteredException.class)
public void test_creation_wrong_definition()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        assertNotNull(sequencer);

        SnowcastEpoch epoch = SnowcastEpoch.byTimestamp(System.currentTimeMillis());
        buildSnowcastSequencer(snowcast, epoch);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 9
Source File: BasicTestCase.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 {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        assertNotNull(sequencer);

        sequencer.attachLogicalNode();
    } finally {
        factory.shutdownAll();
    }
}
 
Example 10
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test(expected = SnowcastStateException.class)
public void test_destroyed_state()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

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

        snowcast.destroySequencer(sequencer);
        sequencer.next();

    } finally {
        factory.shutdownAll();
    }
}
 
Example 11
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_simple_sequencer_initialization_declarative()
        throws Exception {

    ClassLoader classLoader = BasicTestCase.class.getClassLoader();
    InputStream stream = classLoader.getResourceAsStream("hazelcast-node-configuration.xml");
    Config config = new XmlConfigBuilder(stream).build();

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);

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

        assertNotNull(sequencer);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 12
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_simple_sequencer_initialization()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        assertNotNull(sequencer);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 13
Source File: BasicTestCase.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 {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        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 {
        factory.shutdownAll();
    }
}
 
Example 14
Source File: SnowcastSequenceUtilsTestCase.java    From snowcast with Apache License 2.0 5 votes vote down vote up
@Test
public void test_comparator_first_higher_by_counter()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

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

        int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(SnowcastConstants.DEFAULT_MAX_LOGICAL_NODES_13_BITS);
        int shifting = calculateLogicalNodeShifting(boundedNodeCount);
        long sequence1 = generateSequenceId(10000, 1, 2, shifting);
        long sequence2 = generateSequenceId(10000, 1, 1, shifting);

        Comparator<Long> comparator = SnowcastSequenceUtils.snowcastSequenceComparator(sequencer);

        assertEquals(1, comparator.compare(sequence1, sequence2));
    } finally {
        factory.shutdownAll();
    }
}
 
Example 15
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 5 votes vote down vote up
@Test
public void test_single_id_generation()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);
    } finally {
        factory.shutdownAll();
    }
}
 
Example 16
Source File: MultiNodeTestCase.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 {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    factory.newHazelcastInstance();

    try {
        String sequencerName = generateKeyNotOwnedBy(hazelcastInstance);
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast, sequencerName);

        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 {
        factory.shutdownAll();
    }
}
 
Example 17
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 18
Source File: MultiNodeTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_distribute_destroy_node1()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance();

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

        String sequencerName = generateKeyNotOwnedBy(hazelcastInstance1);
        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        final SnowcastSequencer sequencer1 = buildSnowcastSequencer(snowcast1, sequencerName, epoch);

        assertNotNull(sequencer1);
        assertNotNull(sequencer1.next());

        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);
        final SnowcastSequencer sequencer2 = buildSnowcastSequencer(snowcast2, sequencerName, epoch);

        assertNotNull(sequencer2);
        assertNotNull(sequencer2.next());

        sequencer1.next();
        sequencer2.next();

        snowcast1.destroySequencer(sequencer1);

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

                assertEquals(SnowcastSequenceState.Destroyed, sequencer1.getSequencerState());
                assertEquals(SnowcastSequenceState.Destroyed, sequencer2.getSequencerState());
            }
        });

    } finally {
        factory.shutdownAll();
    }
}
 
Example 19
Source File: MultiNodeTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_distribute_destroy_node3()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(3);
    HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance3 = factory.newHazelcastInstance();

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

        String sequencerName = generateKeyOwnedBy(hazelcastInstance2);
        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        final SnowcastSequencer sequencer1 = buildSnowcastSequencer(snowcast1, sequencerName, epoch);

        assertNotNull(sequencer1);
        assertNotNull(sequencer1.next());

        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);
        final SnowcastSequencer sequencer2 = buildSnowcastSequencer(snowcast2, sequencerName, epoch);

        assertNotNull(sequencer2);
        assertNotNull(sequencer2.next());

        Snowcast snowcast3 = SnowcastSystem.snowcast(hazelcastInstance3);
        final SnowcastSequencer sequencer3 = buildSnowcastSequencer(snowcast3, sequencerName, epoch);

        assertNotNull(sequencer3);
        assertNotNull(sequencer3.next());

        assertNotEquals(sequencer1, sequencer2);
        assertNotEquals(sequencer1, sequencer3);
        assertNotEquals(sequencer2, sequencer3);

        sequencer1.next();
        sequencer2.next();
        sequencer3.next();

        snowcast3.destroySequencer(sequencer3);

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

                assertEquals(SnowcastSequenceState.Destroyed, sequencer1.getSequencerState());
                assertEquals(SnowcastSequenceState.Destroyed, sequencer2.getSequencerState());
                assertEquals(SnowcastSequenceState.Destroyed, sequencer3.getSequencerState());
            }
        });

    } finally {
        factory.shutdownAll();
    }
}
 
Example 20
Source File: MultiNodeTestCase.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Test
public void test_distribute_destroy_node2()
        throws Exception {

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance();
    HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance();

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

        String sequencerName = generateKeyNotOwnedBy(hazelcastInstance1);
        Snowcast snowcast1 = SnowcastSystem.snowcast(hazelcastInstance1);
        final SnowcastSequencer sequencer1 = buildSnowcastSequencer(snowcast1, sequencerName, epoch);

        assertNotNull(sequencer1);
        assertNotNull(sequencer1.next());

        Snowcast snowcast2 = SnowcastSystem.snowcast(hazelcastInstance2);
        final SnowcastSequencer sequencer2 = buildSnowcastSequencer(snowcast2, sequencerName, epoch);

        assertNotNull(sequencer2);
        assertNotNull(sequencer2.next());

        assertNotEquals(sequencer1, sequencer2);

        sequencer1.next();
        sequencer2.next();

        snowcast2.destroySequencer(sequencer2);

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

                assertEquals(SnowcastSequenceState.Destroyed, sequencer1.getSequencerState());
                assertEquals(SnowcastSequenceState.Destroyed, sequencer2.getSequencerState());
            }
        });

    } finally {
        factory.shutdownAll();
    }
}