Search in sources :

Example 71 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerErrorsTest method errorInRecovering4.

@Test
public void errorInRecovering4() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    factory = new ManagedLedgerFactoryImpl(bkc, zkc);
    zkc.failAfter(1, Code.CONNECTIONLOSS);
    try {
        ledger = factory.open("my_test_ledger");
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // It should be fine now
    ledger = factory.open("my_test_ledger");
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 72 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerSingleBookieTest method simple.

// (timeOut = 20000)
@Test
public void simple() throws Exception {
    ManagedLedgerConfig config = new ManagedLedgerConfig().setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataWriteQuorumSize(1).setMetadataAckQuorumSize(1);
    ManagedLedger ledger = factory.open("my_test_ledger", config);
    assertEquals(ledger.getNumberOfEntries(), 0);
    assertEquals(ledger.getTotalSize(), 0);
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    assertEquals(ledger.getNumberOfEntries(), 1);
    assertEquals(ledger.getTotalSize(), "dummy-entry-1".getBytes(Encoding).length);
    ManagedCursor cursor = ledger.openCursor("c1");
    assertEquals(cursor.hasMoreEntries(), false);
    assertEquals(cursor.readEntries(100), new ArrayList<Entry>());
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    assertEquals(cursor.hasMoreEntries(), true);
    List<Entry> entries = cursor.readEntries(100);
    assertEquals(entries.size(), 1);
    entries.forEach(e -> e.release());
    entries = cursor.readEntries(100);
    assertEquals(entries.size(), 0);
    entries.forEach(e -> e.release());
    ledger.close();
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 73 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class PersistentTopicConcurrentTest method setup.

@BeforeMethod
public void setup(Method m) throws Exception {
    super.setUp(m);
    ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
    PulsarService pulsar = spy(new PulsarService(svcConfig));
    doReturn(svcConfig).when(pulsar).getConfiguration();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    final ManagedCursor cursor = ledger.openCursor("c1");
    cursorMock = cursor;
    ledgerMock = ledger;
    mlFactoryMock = factory;
    doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
    ZooKeeper mockZk = mock(ZooKeeper.class);
    doReturn(mockZk).when(pulsar).getZkClient();
    brokerService = spy(new BrokerService(pulsar));
    doReturn(brokerService).when(pulsar).getBrokerService();
    serverCnx = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnx).isActive();
    NamespaceService nsSvc = mock(NamespaceService.class);
    doReturn(nsSvc).when(pulsar).getNamespaceService();
    doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
    doReturn(true).when(nsSvc).isServiceUnitActive(any(DestinationName.class));
    final List<Position> addedEntries = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        Position pos = ledger.addEntry("entry".getBytes());
        addedEntries.add(pos);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ServerCnx(com.yahoo.pulsar.broker.service.ServerCnx) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 74 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class NamespaceServiceTest method testIsServiceUnitDisabled.

@Test
public void testIsServiceUnitDisabled() throws Exception {
    OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
    ManagedLedger ledger = mock(ManagedLedger.class);
    when(ledger.getCursors()).thenReturn(Lists.newArrayList());
    doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
    Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
    ownership.setAccessible(true);
    ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
    NamespaceService namespaceService = pulsar.getNamespaceService();
    NamespaceName nsname = new NamespaceName("pulsar/global/ns1");
    DestinationName dn = DestinationName.get("persistent://pulsar/global/ns1/topic-1");
    NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname);
    NamespaceBundle originalBundle = bundles.findBundle(dn);
    assertFalse(namespaceService.isNamespaceBundleDisabled(originalBundle));
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Field(java.lang.reflect.Field) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) NamespaceBundles(com.yahoo.pulsar.common.naming.NamespaceBundles) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) Test(org.testng.annotations.Test)

Example 75 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class PersistentTopicTest method testCreateTopic.

@Test
public void testCreateTopic() throws Exception {
    final ManagedLedger ledgerMock = mock(ManagedLedger.class);
    doReturn(new ArrayList<Object>()).when(ledgerMock).getCursors();
    final String topicName = "persistent://prop/use/ns-abc/topic1";
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ((OpenLedgerCallback) invocationOnMock.getArguments()[2]).openLedgerComplete(ledgerMock, null);
            return null;
        }
    }).when(mlFactoryMock).asyncOpen(anyString(), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), anyObject());
    CompletableFuture<Void> future = brokerService.getTopic(topicName).thenAccept(topic -> {
        assertTrue(topic.toString().contains(topicName));
    }).exceptionally((t) -> {
        fail("should not fail");
        return null;
    });
    // wait for completion
    try {
        future.get(1, TimeUnit.SECONDS);
    } catch (Exception e) {
        fail("Should not fail or time out");
    }
}
Also used : SubType(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSubscribe.SubType) PersistentDispatcherMultipleConsumers(com.yahoo.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) URL(java.net.URL) CloseCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) Policies(com.yahoo.pulsar.common.policies.data.Policies) AfterMethod(org.testng.annotations.AfterMethod) Unpooled(io.netty.buffer.Unpooled) Future(java.util.concurrent.Future) OpenCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Mockito.atLeast(org.mockito.Mockito.atLeast) DeleteCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCursorCallback) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarClientImpl(com.yahoo.pulsar.client.impl.PulsarClientImpl) PulsarClient(com.yahoo.pulsar.client.api.PulsarClient) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Method(java.lang.reflect.Method) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ZooKeeper(org.apache.zookeeper.ZooKeeper) CyclicBarrier(java.util.concurrent.CyclicBarrier) PersistentSubscription(com.yahoo.pulsar.broker.service.persistent.PersistentSubscription) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.doNothing(org.mockito.Mockito.doNothing) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) Matchers.any(org.mockito.Matchers.any) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) VerificationMode(org.mockito.verification.VerificationMode) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) AdminResource(com.yahoo.pulsar.broker.admin.AdminResource) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) Optional(java.util.Optional) CommandSubscribe(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSubscribe) Mockito.mock(org.mockito.Mockito.mock) DeleteLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteLedgerCallback) Assert.assertNull(org.testng.Assert.assertNull) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) Assert.assertEquals(org.testng.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ProducerConfiguration(com.yahoo.pulsar.client.api.ProducerConfiguration) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) Assert(org.testng.Assert) ByteBuf(io.netty.buffer.ByteBuf) Matchers.anyObject(org.mockito.Matchers.anyObject) ConcurrentOpenHashMap(com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashMap) PowerMockito(org.powermock.api.mockito.PowerMockito) ExecutorService(java.util.concurrent.ExecutorService) NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) PersistentReplicator(com.yahoo.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) ZooKeeperDataCache(com.yahoo.pulsar.zookeeper.ZooKeeperDataCache) Matchers.matches(org.mockito.Matchers.matches) Assert.fail(org.testng.Assert.fail) PersistentDispatcherSingleActiveConsumer(com.yahoo.pulsar.broker.service.persistent.PersistentDispatcherSingleActiveConsumer) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) MessageMetadata(com.yahoo.pulsar.common.api.proto.PulsarApi.MessageMetadata) OpenLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) Assert.assertTrue(org.testng.Assert.assertTrue) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Matchers.anyString(org.mockito.Matchers.anyString) TimeoutException(java.util.concurrent.TimeoutException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ExecutionException(java.util.concurrent.ExecutionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyObject(org.mockito.Matchers.anyObject) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) OpenLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback) Test(org.testng.annotations.Test)

Aggregations

ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)363 Test (org.testng.annotations.Test)354 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)262 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)198 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)180 Position (org.apache.bookkeeper.mledger.Position)167 Entry (org.apache.bookkeeper.mledger.Entry)151 CountDownLatch (java.util.concurrent.CountDownLatch)117 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)98 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)74 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)66 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)59 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)58 ArrayList (java.util.ArrayList)57 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)57 Future (java.util.concurrent.Future)56 AtomicReference (java.util.concurrent.atomic.AtomicReference)55 ExecutorService (java.util.concurrent.ExecutorService)54 BKException (org.apache.bookkeeper.client.BKException)54