コード例 #1
0
  @Test
  public void testDurableSubscription() {
    HazelcastInstance local = createHazelcastInstance();

    ITopic<String> topic = local.getReliableTopic("topic");
    final DurableMessageListener<String> listener = new DurableMessageListener<String>();

    String id = topic.addMessageListener(listener);
    topic.publish("item1");

    assertTrueEventually(
        new AssertTask() {
          @Override
          public void run() throws Exception {
            assertTrue(listener.objects.contains("item1"));
          }
        });

    topic.removeMessageListener(id);

    // todo: this part is still racy because we don't know when the listener is terminated.
    topic.publish("item2");
    topic.publish("item3");

    topic.addMessageListener(listener);

    assertTrueEventually(
        new AssertTask() {
          @Override
          public void run() throws Exception {
            assertEquals(asList("item1", "item2", "item3"), listener.objects);
            assertEquals(asList(0l, 1l, 2l), listener.sequences);
          }
        });
  }
コード例 #2
0
  @Before
  public void setupCluster() {
    Config config = new Config();
    config.addRingBufferConfig(
        new RingbufferConfig("when*").setCapacity(100).setTimeToLiveSeconds(5));
    hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenError_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.ERROR));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenDiscardOldest_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_OLDEST));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenDiscardNewest_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_NEWEST));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenBlock_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.BLOCK));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);

    serializationService = ((HazelcastClientProxy) client).getSerializationService();

    String topicName = getTestMethodName();
    topic = client.<String>getReliableTopic(topicName);

    ringbuffer = ((ClientReliableTopicProxy<String>) topic).getRingbuffer();
  }
コード例 #3
0
  @Before
  public void setup() {
    ReliableTopicConfig topicConfig = new ReliableTopicConfig("reliableTopic*");

    RingbufferConfig ringbufferConfig = new RingbufferConfig(topicConfig.getName());
    ringbufferConfig.setCapacity(CAPACITY);

    Config config = new Config();
    config.addReliableTopicConfig(topicConfig);
    config.addRingBufferConfig(ringbufferConfig);

    HazelcastInstance[] instances = newInstances(config);
    local = instances[0];
    HazelcastInstance target = instances[instances.length - 1];

    String name = randomNameOwnedBy(target, "reliableTopic");
    topic = (ReliableTopicProxy<String>) local.<String>getReliableTopic(name);
  }