Search in sources :

Example 1 with CounterBrokerInterceptor

use of org.apache.pulsar.broker.intercept.CounterBrokerInterceptor in project pulsar by apache.

the class OwnerShipForCurrentServerTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 2 with CounterBrokerInterceptor

use of org.apache.pulsar.broker.intercept.CounterBrokerInterceptor in project pulsar by yahoo.

the class OwnerShipForCurrentServerTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 3 with CounterBrokerInterceptor

use of org.apache.pulsar.broker.intercept.CounterBrokerInterceptor in project pulsar by yahoo.

the class TransactionTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 4 with CounterBrokerInterceptor

use of org.apache.pulsar.broker.intercept.CounterBrokerInterceptor in project incubator-pulsar by apache.

the class TransactionTest method testEndTxnWhenCommittingOrAborting.

@Test
public void testEndTxnWhenCommittingOrAborting() throws Exception {
    Transaction commitTxn = pulsarClient.newTransaction().withTransactionTimeout(5, TimeUnit.SECONDS).build().get();
    Transaction abortTxn = pulsarClient.newTransaction().withTransactionTimeout(5, TimeUnit.SECONDS).build().get();
    Class<TransactionImpl> transactionClass = TransactionImpl.class;
    Field field = transactionClass.getDeclaredField("state");
    field.setAccessible(true);
    field.set(commitTxn, TransactionImpl.State.COMMITTING);
    field.set(abortTxn, TransactionImpl.State.ABORTING);
    BrokerInterceptor listener = getPulsarServiceList().get(0).getBrokerInterceptor();
    assertEquals(((CounterBrokerInterceptor) listener).getTxnCount(), 2);
    abortTxn.abort().get();
    assertEquals(((CounterBrokerInterceptor) listener).getAbortedTxnCount(), 1);
    commitTxn.commit().get();
    assertEquals(((CounterBrokerInterceptor) listener).getCommittedTxnCount(), 1);
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor) CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) Field(java.lang.reflect.Field) Transaction(org.apache.pulsar.client.api.transaction.Transaction) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) Test(org.testng.annotations.Test)

Example 5 with CounterBrokerInterceptor

use of org.apache.pulsar.broker.intercept.CounterBrokerInterceptor in project incubator-pulsar by apache.

the class TransactionTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Aggregations

CounterBrokerInterceptor (org.apache.pulsar.broker.intercept.CounterBrokerInterceptor)11 SameThreadOrderedSafeExecutor (org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor)6 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)6 ZKMetadataStore (org.apache.pulsar.metadata.impl.ZKMetadataStore)6 MockZooKeeperSession (org.apache.zookeeper.MockZooKeeperSession)6 Field (java.lang.reflect.Field)2 BrokerInterceptor (org.apache.pulsar.broker.intercept.BrokerInterceptor)2 Transaction (org.apache.pulsar.client.api.transaction.Transaction)2 TransactionImpl (org.apache.pulsar.client.impl.transaction.TransactionImpl)2 Test (org.testng.annotations.Test)2