Search in sources :

Example 1 with ProducerImpl

use of com.yahoo.pulsar.client.impl.ProducerImpl in project pulsar by yahoo.

the class PersistentReplicator method getStats.

public ReplicatorStats getStats() {
    stats.replicationBacklog = cursor.getNumberOfEntriesInBacklog();
    stats.connected = producer != null && producer.isConnected();
    stats.replicationDelayInSeconds = getReplicationDelayInSeconds();
    ProducerImpl producer = this.producer;
    if (producer != null) {
        stats.outboundConnection = producer.getConnectionId();
        stats.outboundConnectedSince = producer.getConnectedSince();
    } else {
        stats.outboundConnection = null;
        stats.outboundConnectedSince = null;
    }
    return stats;
}
Also used : ProducerImpl(com.yahoo.pulsar.client.impl.ProducerImpl)

Example 2 with ProducerImpl

use of com.yahoo.pulsar.client.impl.ProducerImpl in project pulsar by yahoo.

the class ReplicatorTest method testReplicatorProducerClosing.

@Test(priority = 5)
public void testReplicatorProducerClosing() throws Exception {
    log.info("--- Starting ReplicatorTest::testDeleteReplicatorFailure ---");
    final String topicName = "persistent://pulsar/global/ns/repltopicbatch";
    final DestinationName dest = DestinationName.get(topicName);
    MessageProducer producer1 = new MessageProducer(url1, dest);
    PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(topicName);
    final String replicatorClusterName = topic.getReplicators().keys().get(0);
    PersistentReplicator replicator = topic.getPersistentReplicator(replicatorClusterName);
    pulsar2.close();
    pulsar3.close();
    replicator.disconnect(false);
    Thread.sleep(100);
    Field field = PersistentReplicator.class.getDeclaredField("producer");
    field.setAccessible(true);
    ProducerImpl producer = (ProducerImpl) field.get(replicator);
    assertNull(producer);
}
Also used : Field(java.lang.reflect.Field) ProducerImpl(com.yahoo.pulsar.client.impl.ProducerImpl) PersistentReplicator(com.yahoo.pulsar.broker.service.persistent.PersistentReplicator) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) Test(org.testng.annotations.Test)

Example 3 with ProducerImpl

use of com.yahoo.pulsar.client.impl.ProducerImpl in project pulsar by yahoo.

the class PersistentTopicE2ETest method testProducerQueueFullBlocking.

@Test
public void testProducerQueueFullBlocking() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic-xyzx";
    final int messages = 10;
    PulsarClient client = PulsarClient.create(brokerUrl.toString());
    // 1. Producer connect
    ProducerConfiguration producerConfiguration = new ProducerConfiguration().setMaxPendingMessages(messages).setBlockIfQueueFull(true).setSendTimeout(1, TimeUnit.SECONDS);
    ProducerImpl producer = (ProducerImpl) client.createProducer(topicName, producerConfiguration);
    // 2. Stop broker
    cleanup();
    // 2. producer publish messages
    long startTime = System.nanoTime();
    for (int i = 0; i < messages; i++) {
        // Should never block
        producer.sendAsync("msg".getBytes());
    }
    // Verify thread was not blocked
    long delayNs = System.nanoTime() - startTime;
    assertTrue(delayNs < TimeUnit.SECONDS.toNanos(1));
    assertEquals(producer.getPendingQueueSize(), messages);
    // Next send operation must block, until all the messages in the queue expire
    startTime = System.nanoTime();
    producer.sendAsync("msg".getBytes());
    delayNs = System.nanoTime() - startTime;
    assertTrue(delayNs > TimeUnit.MILLISECONDS.toNanos(500));
    assertTrue(delayNs < TimeUnit.MILLISECONDS.toNanos(1500));
    assertEquals(producer.getPendingQueueSize(), 1);
    // 4. producer disconnect
    producer.close();
    client.close();
    // 5. Restart broker
    setup();
}
Also used : ProducerImpl(com.yahoo.pulsar.client.impl.ProducerImpl) ProducerConfiguration(com.yahoo.pulsar.client.api.ProducerConfiguration) PulsarClient(com.yahoo.pulsar.client.api.PulsarClient) Test(org.testng.annotations.Test)

Example 4 with ProducerImpl

use of com.yahoo.pulsar.client.impl.ProducerImpl in project pulsar by yahoo.

the class PersistentTopicE2ETest method testProducerQueueFullNonBlocking.

@Test
public void testProducerQueueFullNonBlocking() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic-xyzx";
    final int messages = 10;
    // 1. Producer connect
    PulsarClient client = PulsarClient.create(brokerUrl.toString());
    ProducerConfiguration producerConfiguration = new ProducerConfiguration().setMaxPendingMessages(messages).setBlockIfQueueFull(false).setSendTimeout(1, TimeUnit.SECONDS);
    ProducerImpl producer = (ProducerImpl) client.createProducer(topicName, producerConfiguration);
    // 2. Stop broker
    cleanup();
    // 2. producer publish messages
    long startTime = System.nanoTime();
    for (int i = 0; i < messages; i++) {
        // Should never block
        producer.sendAsync("msg".getBytes());
    }
    // Verify thread was not blocked
    long delayNs = System.nanoTime() - startTime;
    assertTrue(delayNs < TimeUnit.SECONDS.toNanos(1));
    assertEquals(producer.getPendingQueueSize(), messages);
    // Next send operation must fail and not block
    startTime = System.nanoTime();
    try {
        producer.send("msg".getBytes());
        fail("Send should have failed");
    } catch (PulsarClientException.ProducerQueueIsFullError e) {
    // Expected
    }
    delayNs = System.nanoTime() - startTime;
    assertTrue(delayNs < TimeUnit.SECONDS.toNanos(1));
    assertEquals(producer.getPendingQueueSize(), messages);
    // 4. producer disconnect
    producer.close();
    client.close();
    // 5. Restart broker
    setup();
}
Also used : ProducerImpl(com.yahoo.pulsar.client.impl.ProducerImpl) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) ProducerConfiguration(com.yahoo.pulsar.client.api.ProducerConfiguration) PulsarClient(com.yahoo.pulsar.client.api.PulsarClient) Test(org.testng.annotations.Test)

Example 5 with ProducerImpl

use of com.yahoo.pulsar.client.impl.ProducerImpl in project pulsar by yahoo.

the class ReplicatorTest method testCloseReplicatorStartProducer.

/**
     * It verifies that PersistentReplicator considers CursorAlreadyClosedException as non-retriable-read exception and
     * it should closed the producer as cursor is already closed because replicator is already deleted.
     * 
     * @throws Exception
     */
@Test(timeOut = 5000)
public void testCloseReplicatorStartProducer() throws Exception {
    DestinationName dest = DestinationName.get("persistent://pulsar/global/ns1/closeCursor");
    // Producer on r1
    MessageProducer producer1 = new MessageProducer(url1, dest);
    // Consumer on r1
    MessageConsumer consumer1 = new MessageConsumer(url1, dest);
    // Consumer on r2
    MessageConsumer consumer2 = new MessageConsumer(url2, dest);
    // Replicator for r1 -> r2
    PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(dest.toString());
    PersistentReplicator replicator = topic.getPersistentReplicator("r2");
    // close the cursor
    Field cursorField = PersistentReplicator.class.getDeclaredField("cursor");
    cursorField.setAccessible(true);
    ManagedCursor cursor = (ManagedCursor) cursorField.get(replicator);
    cursor.close();
    // try to read entries
    CountDownLatch latch = new CountDownLatch(1);
    producer1.produce(10);
    cursor.asyncReadEntriesOrWait(10, new ReadEntriesCallback() {

        @Override
        public void readEntriesComplete(List<Entry> entries, Object ctx) {
            latch.countDown();
            fail("it should have been failed");
        }

        @Override
        public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
            latch.countDown();
            assertTrue(exception instanceof CursorAlreadyClosedException);
        }
    }, null);
    // replicator-readException: cursorAlreadyClosed
    replicator.readEntriesFailed(new CursorAlreadyClosedException("Cursor already closed exception"), null);
    // wait replicator producer to be closed
    Thread.sleep(1000);
    // Replicator producer must be closed
    Field producerField = PersistentReplicator.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    ProducerImpl replicatorProducer = (ProducerImpl) producerField.get(replicator);
    assertEquals(replicatorProducer, null);
    producer1.close();
    consumer1.close();
    consumer2.close();
}
Also used : ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) PersistentReplicator(com.yahoo.pulsar.broker.service.persistent.PersistentReplicator) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Field(java.lang.reflect.Field) ProducerImpl(com.yahoo.pulsar.client.impl.ProducerImpl) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) CursorAlreadyClosedException(org.apache.bookkeeper.mledger.ManagedLedgerException.CursorAlreadyClosedException) Test(org.testng.annotations.Test)

Aggregations

ProducerImpl (com.yahoo.pulsar.client.impl.ProducerImpl)5 Test (org.testng.annotations.Test)4 PersistentReplicator (com.yahoo.pulsar.broker.service.persistent.PersistentReplicator)2 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)2 ProducerConfiguration (com.yahoo.pulsar.client.api.ProducerConfiguration)2 PulsarClient (com.yahoo.pulsar.client.api.PulsarClient)2 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)2 Field (java.lang.reflect.Field)2 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ReadEntriesCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback)1 Entry (org.apache.bookkeeper.mledger.Entry)1 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 CursorAlreadyClosedException (org.apache.bookkeeper.mledger.ManagedLedgerException.CursorAlreadyClosedException)1