Search in sources :

Example 1 with MLPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider in project pulsar by apache.

the class TransactionTest method testSubscriptionRecreateTopic.

@Test
public void testSubscriptionRecreateTopic() throws PulsarAdminException, NoSuchFieldException, IllegalAccessException, PulsarClientException {
    String topic = "persistent://pulsar/system/testReCreateTopic";
    String subName = "sub_testReCreateTopic";
    int retentionSizeInMbSetTo = 5;
    int retentionSizeInMbSetTopic = 6;
    int retentionSizeInMinutesSetTo = 5;
    int retentionSizeInMinutesSetTopic = 6;
    admin.topics().createNonPartitionedTopic(topic);
    PulsarService pulsarService = super.getPulsarServiceList().get(0);
    pulsarService.getBrokerService().getTopics().clear();
    ManagedLedgerFactory managedLedgerFactory = pulsarService.getBrokerService().getManagedLedgerFactory();
    Field field = ManagedLedgerFactoryImpl.class.getDeclaredField("ledgers");
    field.setAccessible(true);
    ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>> ledgers = (ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>>) field.get(managedLedgerFactory);
    ledgers.remove(TopicName.get(topic).getPersistenceNamingEncoding());
    try {
        admin.topics().createNonPartitionedTopic(topic);
        Assert.fail();
    } catch (PulsarAdminException.ConflictException e) {
        log.info("Cann`t create topic again");
    }
    admin.topics().setRetention(topic, new RetentionPolicies(retentionSizeInMinutesSetTopic, retentionSizeInMbSetTopic));
    pulsarClient.newConsumer().topic(topic).subscriptionName(subName).subscribe();
    pulsarService.getBrokerService().getTopicIfExists(topic).thenAccept(option -> {
        if (!option.isPresent()) {
            log.error("Failed o get Topic named: {}", topic);
            Assert.fail();
        }
        PersistentTopic originPersistentTopic = (PersistentTopic) option.get();
        String pendingAckTopicName = MLPendingAckStore.getTransactionPendingAckStoreSuffix(originPersistentTopic.getName(), subName);
        try {
            admin.topics().setRetention(pendingAckTopicName, new RetentionPolicies(retentionSizeInMinutesSetTo, retentionSizeInMbSetTo));
        } catch (PulsarAdminException e) {
            log.error("Failed to get./setRetention of topic with Exception:" + e);
            Assert.fail();
        }
        PersistentSubscription subscription = originPersistentTopic.getSubscription(subName);
        subscription.getPendingAckManageLedger().thenAccept(managedLedger -> {
            long retentionSize = managedLedger.getConfig().getRetentionSizeInMB();
            if (!originPersistentTopic.getTopicPolicies().isPresent()) {
                log.error("Failed to getTopicPolicies of :" + originPersistentTopic);
                Assert.fail();
            }
            TopicPolicies topicPolicies = originPersistentTopic.getTopicPolicies().get();
            Assert.assertEquals(retentionSizeInMbSetTopic, retentionSize);
            MLPendingAckStoreProvider mlPendingAckStoreProvider = new MLPendingAckStoreProvider();
            CompletableFuture<PendingAckStore> future = mlPendingAckStoreProvider.newPendingAckStore(subscription);
            future.thenAccept(pendingAckStore -> {
                ((MLPendingAckStore) pendingAckStore).getManagedLedger().thenAccept(managedLedger1 -> {
                    Assert.assertEquals(managedLedger1.getConfig().getRetentionSizeInMB(), retentionSizeInMbSetTo);
                });
            });
        });
    });
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) MLPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) Field(java.lang.reflect.Field) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) CompletableFuture(java.util.concurrent.CompletableFuture) PulsarService(org.apache.pulsar.broker.PulsarService) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) PendingAckStore(org.apache.pulsar.broker.transaction.pendingack.PendingAckStore) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 2 with MLPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider in project incubator-pulsar by apache.

the class TransactionTest method testSubscriptionRecreateTopic.

@Test
public void testSubscriptionRecreateTopic() throws PulsarAdminException, NoSuchFieldException, IllegalAccessException, PulsarClientException {
    String topic = "persistent://pulsar/system/testReCreateTopic";
    String subName = "sub_testReCreateTopic";
    int retentionSizeInMbSetTo = 5;
    int retentionSizeInMbSetTopic = 6;
    int retentionSizeInMinutesSetTo = 5;
    int retentionSizeInMinutesSetTopic = 6;
    admin.topics().createNonPartitionedTopic(topic);
    PulsarService pulsarService = super.getPulsarServiceList().get(0);
    pulsarService.getBrokerService().getTopics().clear();
    ManagedLedgerFactory managedLedgerFactory = pulsarService.getBrokerService().getManagedLedgerFactory();
    Field field = ManagedLedgerFactoryImpl.class.getDeclaredField("ledgers");
    field.setAccessible(true);
    ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>> ledgers = (ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>>) field.get(managedLedgerFactory);
    ledgers.remove(TopicName.get(topic).getPersistenceNamingEncoding());
    try {
        admin.topics().createNonPartitionedTopic(topic);
        Assert.fail();
    } catch (PulsarAdminException.ConflictException e) {
        log.info("Cann`t create topic again");
    }
    admin.topics().setRetention(topic, new RetentionPolicies(retentionSizeInMinutesSetTopic, retentionSizeInMbSetTopic));
    pulsarClient.newConsumer().topic(topic).subscriptionName(subName).subscribe();
    pulsarService.getBrokerService().getTopicIfExists(topic).thenAccept(option -> {
        if (!option.isPresent()) {
            log.error("Failed o get Topic named: {}", topic);
            Assert.fail();
        }
        PersistentTopic originPersistentTopic = (PersistentTopic) option.get();
        String pendingAckTopicName = MLPendingAckStore.getTransactionPendingAckStoreSuffix(originPersistentTopic.getName(), subName);
        try {
            admin.topics().setRetention(pendingAckTopicName, new RetentionPolicies(retentionSizeInMinutesSetTo, retentionSizeInMbSetTo));
        } catch (PulsarAdminException e) {
            log.error("Failed to get./setRetention of topic with Exception:" + e);
            Assert.fail();
        }
        PersistentSubscription subscription = originPersistentTopic.getSubscription(subName);
        subscription.getPendingAckManageLedger().thenAccept(managedLedger -> {
            long retentionSize = managedLedger.getConfig().getRetentionSizeInMB();
            if (!originPersistentTopic.getTopicPolicies().isPresent()) {
                log.error("Failed to getTopicPolicies of :" + originPersistentTopic);
                Assert.fail();
            }
            TopicPolicies topicPolicies = originPersistentTopic.getTopicPolicies().get();
            Assert.assertEquals(retentionSizeInMbSetTopic, retentionSize);
            MLPendingAckStoreProvider mlPendingAckStoreProvider = new MLPendingAckStoreProvider();
            CompletableFuture<PendingAckStore> future = mlPendingAckStoreProvider.newPendingAckStore(subscription);
            future.thenAccept(pendingAckStore -> {
                ((MLPendingAckStore) pendingAckStore).getManagedLedger().thenAccept(managedLedger1 -> {
                    Assert.assertEquals(managedLedger1.getConfig().getRetentionSizeInMB(), retentionSizeInMbSetTo);
                });
            });
        });
    });
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) MLPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) Field(java.lang.reflect.Field) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) CompletableFuture(java.util.concurrent.CompletableFuture) PulsarService(org.apache.pulsar.broker.PulsarService) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) PendingAckStore(org.apache.pulsar.broker.transaction.pendingack.PendingAckStore) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 3 with MLPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider in project pulsar by yahoo.

the class TransactionTest method testSubscriptionRecreateTopic.

@Test
public void testSubscriptionRecreateTopic() throws PulsarAdminException, NoSuchFieldException, IllegalAccessException, PulsarClientException {
    String topic = "persistent://pulsar/system/testReCreateTopic";
    String subName = "sub_testReCreateTopic";
    int retentionSizeInMbSetTo = 5;
    int retentionSizeInMbSetTopic = 6;
    int retentionSizeInMinutesSetTo = 5;
    int retentionSizeInMinutesSetTopic = 6;
    admin.topics().createNonPartitionedTopic(topic);
    PulsarService pulsarService = super.getPulsarServiceList().get(0);
    pulsarService.getBrokerService().getTopics().clear();
    ManagedLedgerFactory managedLedgerFactory = pulsarService.getBrokerService().getManagedLedgerFactory();
    Field field = ManagedLedgerFactoryImpl.class.getDeclaredField("ledgers");
    field.setAccessible(true);
    ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>> ledgers = (ConcurrentHashMap<String, CompletableFuture<ManagedLedgerImpl>>) field.get(managedLedgerFactory);
    ledgers.remove(TopicName.get(topic).getPersistenceNamingEncoding());
    try {
        admin.topics().createNonPartitionedTopic(topic);
        Assert.fail();
    } catch (PulsarAdminException.ConflictException e) {
        log.info("Cann`t create topic again");
    }
    admin.topics().setRetention(topic, new RetentionPolicies(retentionSizeInMinutesSetTopic, retentionSizeInMbSetTopic));
    pulsarClient.newConsumer().topic(topic).subscriptionName(subName).subscribe();
    pulsarService.getBrokerService().getTopicIfExists(topic).thenAccept(option -> {
        if (!option.isPresent()) {
            log.error("Failed o get Topic named: {}", topic);
            Assert.fail();
        }
        PersistentTopic originPersistentTopic = (PersistentTopic) option.get();
        String pendingAckTopicName = MLPendingAckStore.getTransactionPendingAckStoreSuffix(originPersistentTopic.getName(), subName);
        try {
            admin.topics().setRetention(pendingAckTopicName, new RetentionPolicies(retentionSizeInMinutesSetTo, retentionSizeInMbSetTo));
        } catch (PulsarAdminException e) {
            log.error("Failed to get./setRetention of topic with Exception:" + e);
            Assert.fail();
        }
        PersistentSubscription subscription = originPersistentTopic.getSubscription(subName);
        subscription.getPendingAckManageLedger().thenAccept(managedLedger -> {
            long retentionSize = managedLedger.getConfig().getRetentionSizeInMB();
            if (!originPersistentTopic.getTopicPolicies().isPresent()) {
                log.error("Failed to getTopicPolicies of :" + originPersistentTopic);
                Assert.fail();
            }
            TopicPolicies topicPolicies = originPersistentTopic.getTopicPolicies().get();
            Assert.assertEquals(retentionSizeInMbSetTopic, retentionSize);
            MLPendingAckStoreProvider mlPendingAckStoreProvider = new MLPendingAckStoreProvider();
            CompletableFuture<PendingAckStore> future = mlPendingAckStoreProvider.newPendingAckStore(subscription);
            future.thenAccept(pendingAckStore -> {
                ((MLPendingAckStore) pendingAckStore).getManagedLedger().thenAccept(managedLedger1 -> {
                    Assert.assertEquals(managedLedger1.getConfig().getRetentionSizeInMB(), retentionSizeInMbSetTo);
                });
            });
        });
    });
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) MLPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) Field(java.lang.reflect.Field) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) CompletableFuture(java.util.concurrent.CompletableFuture) PulsarService(org.apache.pulsar.broker.PulsarService) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) PendingAckStore(org.apache.pulsar.broker.transaction.pendingack.PendingAckStore) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Aggregations

Field (java.lang.reflect.Field)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 PulsarService (org.apache.pulsar.broker.PulsarService)3 PersistentSubscription (org.apache.pulsar.broker.service.persistent.PersistentSubscription)3 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 PendingAckStore (org.apache.pulsar.broker.transaction.pendingack.PendingAckStore)3 MLPendingAckStore (org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore)3 MLPendingAckStoreProvider (org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStoreProvider)3 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)3 TopicPolicies (org.apache.pulsar.common.policies.data.TopicPolicies)3 Test (org.testng.annotations.Test)3