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