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();
}
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();
}
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();
}
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);
}
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();
}
Aggregations