Search in sources :

Example 21 with RingbufferStoreConfig

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;
}
Also used : RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferConfig(com.hazelcast.config.RingbufferConfig)

Example 22 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with RingbufferStoreConfig

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());
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RingbufferStoreConfig (com.hazelcast.config.RingbufferStoreConfig)28 RingbufferConfig (com.hazelcast.config.RingbufferConfig)19 Config (com.hazelcast.config.Config)16 Test (org.junit.Test)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AttributeConfig (com.hazelcast.config.AttributeConfig)2 AwsConfig (com.hazelcast.config.AwsConfig)2 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)2 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2 CacheSimpleEntryListenerConfig (com.hazelcast.config.CacheSimpleEntryListenerConfig)2 CardinalityEstimatorConfig (com.hazelcast.config.CardinalityEstimatorConfig)2 DataPersistenceConfig (com.hazelcast.config.DataPersistenceConfig)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 DiskTierConfig (com.hazelcast.config.DiskTierConfig)2