use of com.hazelcast.config.RingbufferStoreConfig in project hazelcast by hazelcast.
the class RingbufferStoreFailureConsistencyTest method getConfig.
private static Config getConfig(String ringbufferName, int capacity, RingbufferStoreConfig ringbufferStoreConfig) {
Config config = new Config();
RingbufferConfig rbConfig = config.getRingbufferConfig(ringbufferName).setInMemoryFormat(OBJECT).setBackupCount(1).setCapacity(capacity);
rbConfig.setRingbufferStoreConfig(ringbufferStoreConfig);
return config;
}
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 testRingbufferStoreFactoryIsNotInitialized_whenDisabledInRingbufferStoreConfig.
@Test
public void testRingbufferStoreFactoryIsNotInitialized_whenDisabledInRingbufferStoreConfig() {
final String ringbufferName = randomString();
final SimpleRingbufferStoreFactory rbStoreFactory = new SimpleRingbufferStoreFactory();
final RingbufferStoreConfig rbStoreConfig = new RingbufferStoreConfig().setEnabled(false).setFactoryImplementation(rbStoreFactory);
final Config config = getConfig(ringbufferName, DEFAULT_CAPACITY, OBJECT, rbStoreConfig);
final HazelcastInstance instance = createHazelcastInstance(config);
final Ringbuffer<Object> ringbuffer = instance.getRingbuffer(ringbufferName);
ringbuffer.add(1);
assertEquals("Expected that the RingbufferStore would not be initialized since we disabled it" + " in the RingbufferStoreConfig, but found initialized", 0, rbStoreFactory.stores.size());
}
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 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