Search in sources :

Example 6 with RingbufferStoreConfig

use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.

the class RingbufferStoreTest method testRingbufferStore_getLargestSequenceThrowsException.

@Test(expected = HazelcastException.class)
public void testRingbufferStore_getLargestSequenceThrowsException() throws Exception {
    final String ringbufferName = randomString();
    final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setStoreImplementation(new ExceptionThrowingRingbufferStore(true)).setEnabled(true);
    final Config config = getConfig(ringbufferName, DEFAULT_CAPACITY, OBJECT, rbStoreConfig);
    final HazelcastInstance node = createHazelcastInstance(config);
    node.getRingbuffer(ringbufferName).size();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with RingbufferStoreConfig

use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.

the class RingbufferStoreTest method testRingbufferStore_withBinaryModeOn.

@Test
public void testRingbufferStore_withBinaryModeOn() throws InterruptedException {
    final String ringbufferName = randomString();
    final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setStoreImplementation(new TestRingbufferStore<Data>()).setEnabled(true);
    final Config config = getConfig(ringbufferName, DEFAULT_CAPACITY, BINARY, rbStoreConfig);
    final HazelcastInstance node = createHazelcastInstance(config);
    final Ringbuffer<Object> ringbuffer = node.getRingbuffer(ringbufferName);
    ringbuffer.add(1);
    ringbuffer.add(2);
    final long lastSequence = ringbuffer.add(3);
    assertEquals(3, ringbuffer.readOne(lastSequence));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with RingbufferStoreConfig

use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.

the class RingbufferStoreTest method testRingbufferStore.

@Test
public void testRingbufferStore() throws Exception {
    final int numItems = 2000;
    final TestRingbufferStore<Integer> rbStore = new TestRingbufferStore<Integer>(2000, 0, 2000);
    final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setEnabled(true).setStoreImplementation(rbStore);
    final Config config = getConfig("testRingbufferStore", DEFAULT_CAPACITY, OBJECT, rbStoreConfig);
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    // add items to the ring buffer and the store and shut down
    final HazelcastInstance instance = factory.newHazelcastInstance(config);
    final Ringbuffer<Object> ringbuffer = instance.getRingbuffer("testRingbufferStore");
    for (int i = 0; i < numItems; i++) {
        ringbuffer.add(i);
    }
    instance.shutdown();
    // now get a new ring buffer and read the items from the store
    final HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final Ringbuffer<Object> ringbuffer2 = instance2.getRingbuffer("testRingbufferStore");
    // the actual ring buffer is empty but we can still load items from it
    assertEquals(0, ringbuffer2.size());
    assertEquals(DEFAULT_CAPACITY, ringbuffer2.remainingCapacity());
    assertEquals(numItems, rbStore.store.size());
    for (int i = 0; i < numItems; i++) {
        assertEquals(i, ringbuffer2.readOne(i));
    }
    rbStore.assertAwait(3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with RingbufferStoreConfig

use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.

the class RingbufferStoreTest method testRingbufferStoreMoreThanCapacity.

@Test
public void testRingbufferStoreMoreThanCapacity() throws Exception {
    final int capacity = 1000;
    final TestRingbufferStore<Integer> rbStore = new TestRingbufferStore<Integer>(capacity * 2, 0, 0);
    final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setEnabled(true).setStoreImplementation(rbStore);
    final Config config = getConfig("testRingbufferStore", capacity, OBJECT, rbStoreConfig);
    final HazelcastInstance instance = createHazelcastInstance(config);
    final Ringbuffer<Object> ringbuffer = instance.getRingbuffer("testRingbufferStore");
    for (int i = 0; i < capacity * 2; i++) {
        ringbuffer.add(i);
    }
    assertEquals(capacity, ringbuffer.size());
    assertEquals(capacity * 2, rbStore.store.size());
    for (int i = 0; i < capacity * 2; i++) {
        assertEquals(i, ringbuffer.readOne(i));
    }
    rbStore.assertAwait(3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with RingbufferStoreConfig

use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.

the class RingbufferStoreTest method testStoreId_writeToMasterAndReadFromBackup.

@Test
public void testStoreId_writeToMasterAndReadFromBackup() throws InterruptedException {
    final IdCheckerRingbufferStore rbStore = new IdCheckerRingbufferStore();
    final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setEnabled(true).setStoreImplementation(rbStore);
    final Config config = getConfig("default", DEFAULT_CAPACITY, OBJECT, rbStoreConfig);
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    warmUpPartitions(instance1, instance2);
    final String name = generateKeyOwnedBy(instance1);
    final Ringbuffer<Object> masterRB = instance1.getRingbuffer(name);
    final HashMap<Long, Integer> addedItems = new HashMap<Long, Integer>();
    for (int i = 0; i < 100; i++) {
        addedItems.put(masterRB.add(i), i);
    }
    terminateInstance(instance1);
    final Ringbuffer<Object> backupRB = instance2.getRingbuffer(name);
    for (Entry<Long, Integer> e : addedItems.entrySet()) {
        assertEquals("The ring buffer returned a different object than the one which was stored", e.getValue(), backupRB.readOne(e.getKey()));
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

RingbufferConfig (com.hazelcast.config.RingbufferConfig)13 RingbufferStoreConfig (com.hazelcast.config.RingbufferStoreConfig)13 Config (com.hazelcast.config.Config)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ArrayList (java.util.ArrayList)1