Search in sources :

Example 1 with Ringbuffer

use of com.hazelcast.ringbuffer.Ringbuffer in project hazelcast by hazelcast.

the class PartitionControlledIdTest method testRingbuffer.

@Test
public void testRingbuffer() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    Ringbuffer ringbuffer = hz.getRingbuffer("ringbuffer@" + partitionKey);
    ringbuffer.add("foo");
    assertEquals("ringbuffer@" + partitionKey, ringbuffer.getName());
    assertEquals(partitionKey, ringbuffer.getPartitionKey());
    RingbufferService service = getNodeEngine(hz).getService(RingbufferService.SERVICE_NAME);
    assertTrue(service.getContainers().containsKey(ringbuffer.getName()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with Ringbuffer

use of com.hazelcast.ringbuffer.Ringbuffer in project hazelcast by hazelcast.

the class HazelcastOSGiInstanceTest method getRingbufferCalledSuccessfullyOverOSGiInstance.

@Test
public void getRingbufferCalledSuccessfullyOverOSGiInstance() {
    Ringbuffer mockRingbuffer = mock(Ringbuffer.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getRingbuffer("my-ringbuffer")).thenReturn(mockRingbuffer);
    assertEquals(mockRingbuffer, hazelcastOSGiInstance.getRingbuffer("my-ringbuffer"));
    verify(mockHazelcastInstance).getRingbuffer("my-ringbuffer");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with Ringbuffer

use of com.hazelcast.ringbuffer.Ringbuffer in project hazelcast by hazelcast.

the class RingbufferServiceTest method rollbackMigration.

@Test
public void rollbackMigration() {
    Ringbuffer ringbuffer = hz.getRingbuffer("foo");
    int partitionId = getPartitionId(hz, ringbuffer.getName());
    PartitionMigrationEvent partitionEvent = new PartitionMigrationEvent(DESTINATION, partitionId, -1, 0);
    service.rollbackMigration(partitionEvent);
    assertEquals(0, service.getContainers().size());
}
Also used : Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with Ringbuffer

use of com.hazelcast.ringbuffer.Ringbuffer in project hazelcast by hazelcast.

the class ReliableTopicCreateTest method testConstruction.

@Test
public void testConstruction() {
    HazelcastInstance hz = createHazelcastInstance();
    RingbufferService ringbufferService = getNodeEngineImpl(hz).getService(RingbufferService.SERVICE_NAME);
    ReliableTopicProxy<String> topic = (ReliableTopicProxy<String>) hz.<String>getReliableTopic("foo");
    Ringbuffer ringbuffer = hz.getRingbuffer(RingbufferService.TOPIC_RB_PREFIX + "foo");
    assertSame(ringbuffer, topic.ringbuffer);
    // make sure the ringbuffer and topic are hooked up correctly
    topic.publish("item1");
    topic.publish("item2");
    assertEquals(0, ringbuffer.headSequence());
    assertEquals(1, ringbuffer.tailSequence());
    ConcurrentMap<String, RingbufferContainer> containers = ringbufferService.getContainers();
    assertEquals(1, containers.size());
    assertTrue(containers.containsKey(ringbuffer.getName()));
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with Ringbuffer

use of com.hazelcast.ringbuffer.Ringbuffer in project hazelcast by hazelcast.

the class ReliableTopicCreateTest method testRingbufferConfiguration.

@Test
public void testRingbufferConfiguration() {
    Config config = new Config();
    RingbufferConfig rbConfig = new RingbufferConfig("foo").setCapacity(21);
    config.addRingBufferConfig(rbConfig);
    HazelcastInstance hz = createHazelcastInstance(config);
    RingbufferService ringbufferService = getNodeEngineImpl(hz).getService(RingbufferService.SERVICE_NAME);
    ReliableTopicProxy topic = (ReliableTopicProxy) hz.getReliableTopic("foo");
    Ringbuffer ringbuffer = hz.getRingbuffer(RingbufferService.TOPIC_RB_PREFIX + "foo");
    assertSame(ringbuffer, topic.ringbuffer);
    assertEquals(21, ringbuffer.capacity());
    // triggers the creation
    ringbuffer.size();
    ConcurrentMap<String, RingbufferContainer> containers = ringbufferService.getContainers();
    assertEquals(1, containers.size());
    assertTrue(containers.containsKey(ringbuffer.getName()));
    RingbufferContainer container = containers.get(ringbuffer.getName());
    assertEquals(rbConfig.getCapacity(), container.getConfig().getCapacity());
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferConfig(com.hazelcast.config.RingbufferConfig) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Ringbuffer (com.hazelcast.ringbuffer.Ringbuffer)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 RingbufferService (com.hazelcast.ringbuffer.impl.RingbufferService)4 Config (com.hazelcast.config.Config)2 ListenerConfig (com.hazelcast.config.ListenerConfig)2 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)2 RingbufferConfig (com.hazelcast.config.RingbufferConfig)2 RingbufferContainer (com.hazelcast.ringbuffer.impl.RingbufferContainer)2 PartitionMigrationEvent (com.hazelcast.spi.PartitionMigrationEvent)1