use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl 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.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.
the class PersistentTopics method getBacklog.
@GET
@Path("{property}/{cluster}/{namespace}/{destination}/backlog")
@ApiOperation(value = "Get estimated backlog for offline topic.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public PersistentOfflineTopicStats getBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
destination = decode(destination);
validateAdminAccessOnProperty(property);
// note that we do not want to load the topic and hence skip validateAdminOperationOnDestination()
try {
policiesCache().get(path("policies", property, cluster, namespace));
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to get topic backlog {}/{}/{}: Namespace does not exist", clientAppId(), property, cluster, namespace);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (Exception e) {
log.error("[{}] Failed to get topic backlog {}/{}/{}", clientAppId(), property, cluster, namespace, e);
throw new RestException(e);
}
DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination);
PersistentOfflineTopicStats offlineTopicStats = null;
try {
offlineTopicStats = pulsar().getBrokerService().getOfflineTopicStat(dn);
if (offlineTopicStats != null) {
// offline topic stat has a cost - so use cached value until TTL
long elapsedMs = System.currentTimeMillis() - offlineTopicStats.statGeneratedAt.getTime();
if (TimeUnit.MINUTES.convert(elapsedMs, TimeUnit.MILLISECONDS) < OFFLINE_TOPIC_STAT_TTL_MINS) {
return offlineTopicStats;
}
}
final ManagedLedgerConfig config = pulsar().getBrokerService().getManagedLedgerConfig(dn).get();
ManagedLedgerOfflineBacklog offlineTopicBacklog = new ManagedLedgerOfflineBacklog(config.getDigestType(), config.getPassword(), pulsar().getAdvertisedAddress(), false);
offlineTopicStats = offlineTopicBacklog.estimateUnloadedTopicBacklog((ManagedLedgerFactoryImpl) pulsar().getManagedLedgerFactory(), dn);
pulsar().getBrokerService().cacheOfflineTopicStats(dn, offlineTopicStats);
} catch (Exception exception) {
throw new RestException(exception);
}
return offlineTopicStats;
}
use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.
the class MockedBookKeeperTestCase method setUp.
@BeforeMethod
public void setUp(Method method) throws Exception {
LOG.info(">>>>>> starting {}", method);
try {
// start bookkeeper service
startBookKeeper();
} catch (Exception e) {
LOG.error("Error setting up", e);
throw e;
}
executor = new OrderedSafeExecutor(2, "test");
cachedExecutor = Executors.newCachedThreadPool();
ManagedLedgerFactoryConfig conf = new ManagedLedgerFactoryConfig();
conf.setUseProtobufBinaryFormatInZK(protobufFormat == ZNodeProtobufFormat.Binary);
factory = new ManagedLedgerFactoryImpl(bkc, zkc, conf);
}
use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.
the class PersistentTopicE2ETest method testUnloadNamespace.
@Test(enabled = false)
public void testUnloadNamespace() throws Exception {
String topicName = "persistent://prop/use/ns-abc/topic-9";
DestinationName destinationName = DestinationName.get(topicName);
pulsarClient.createProducer(topicName);
pulsarClient.close();
assertTrue(pulsar.getBrokerService().getTopicReference(topicName) != null);
assertTrue(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(destinationName.getPersistenceNamingEncoding()));
admin.namespaces().unload("prop/use/ns-abc");
int i = 0;
for (i = 0; i < 30; i++) {
if (pulsar.getBrokerService().getTopicReference(topicName) == null) {
break;
}
Thread.sleep(1000);
}
if (i == 30) {
fail("The topic reference should be null");
}
// ML should have been closed as well
assertFalse(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(destinationName.getPersistenceNamingEncoding()));
}
Aggregations