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();
}
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));
}
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);
}
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);
}
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()));
}
}
Aggregations