use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.
the class MockBookKeeperTestCase method setup.
@Before
public void setup() throws Exception {
mockLedgerMetadataRegistry = new ConcurrentHashMap<>();
mockLedgerData = new ConcurrentHashMap<>();
mockNextLedgerId = new AtomicLong(1);
fencedLedgers = new ConcurrentSkipListSet<>();
scheduler = OrderedScheduler.newSchedulerBuilder().numThreads(4).name("bk-test").build();
executor = OrderedExecutor.newBuilder().build();
bookieWatcher = mock(BookieWatcher.class);
bookieClient = mock(BookieClient.class);
ledgerManager = mock(LedgerManager.class);
ledgerIdGenerator = mock(LedgerIdGenerator.class);
bk = mock(BookKeeper.class);
NullStatsLogger nullStatsLogger = setupLoggers();
failedBookies = new ArrayList<>();
availableBookies = new HashSet<>();
when(bk.getCloseLock()).thenReturn(new ReentrantReadWriteLock());
when(bk.isClosed()).thenReturn(false);
when(bk.getBookieWatcher()).thenReturn(bookieWatcher);
when(bk.getDisableEnsembleChangeFeature()).thenReturn(mock(Feature.class));
when(bk.getExplicitLacInterval()).thenReturn(0);
when(bk.getMainWorkerPool()).thenReturn(executor);
when(bk.getBookieClient()).thenReturn(bookieClient);
when(bk.getScheduler()).thenReturn(scheduler);
when(bk.getReadSpeculativeRequestPolicy()).thenReturn(Optional.absent());
mockBookKeeperGetConf(new ClientConfiguration());
when(bk.getStatsLogger()).thenReturn(nullStatsLogger);
when(bk.getLedgerManager()).thenReturn(ledgerManager);
when(bk.getLedgerIdGenerator()).thenReturn(ledgerIdGenerator);
when(bk.getReturnRc(anyInt())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
setupLedgerIdGenerator();
setupCreateLedgerMetadata();
setupReadLedgerMetadata();
setupWriteLedgerMetadata();
setupRemoveLedgerMetadata();
setupRegisterLedgerMetadataListener();
setupBookieWatcherForNewEnsemble();
setupBookieWatcherForEnsembleChange();
setupBookieClientReadEntry();
setupBookieClientAddEntry();
}
use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.
the class TestWatchEnsembleChange method testWatchMetadataRemoval.
private void testWatchMetadataRemoval(LedgerManagerFactory factory) throws Exception {
@Cleanup final LedgerManager manager = factory.newLedgerManager();
@Cleanup LedgerIdGenerator idGenerator = factory.newLedgerIdGenerator();
final ByteBuffer bbLedgerId = ByteBuffer.allocate(8);
final CountDownLatch createLatch = new CountDownLatch(1);
final CountDownLatch removeLatch = new CountDownLatch(1);
idGenerator.generateLedgerId(new GenericCallback<Long>() {
@Override
public void operationComplete(int rc, final Long lid) {
manager.createLedgerMetadata(lid, new LedgerMetadata(4, 2, 2, digestType, "fpj was here".getBytes()), new BookkeeperInternalCallbacks.GenericCallback<Void>() {
@Override
public void operationComplete(int rc, Void result) {
bbLedgerId.putLong(lid);
bbLedgerId.flip();
createLatch.countDown();
}
});
}
});
assertTrue(createLatch.await(2000, TimeUnit.MILLISECONDS));
final long createdLid = bbLedgerId.getLong();
manager.registerLedgerMetadataListener(createdLid, new LedgerMetadataListener() {
@Override
public void onChanged(long ledgerId, LedgerMetadata metadata) {
assertEquals(ledgerId, createdLid);
assertEquals(metadata, null);
removeLatch.countDown();
}
});
manager.removeLedgerMetadata(createdLid, Version.ANY, new BookkeeperInternalCallbacks.GenericCallback<Void>() {
@Override
public void operationComplete(int rc, Void result) {
assertEquals(rc, BKException.Code.OK);
}
});
assertTrue(removeLatch.await(2000, TimeUnit.MILLISECONDS));
}
use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.
the class LedgerCreateOp method generateLedgerIdAndCreateLedger.
void generateLedgerIdAndCreateLedger() {
// generate a ledgerId
final LedgerIdGenerator ledgerIdGenerator = bk.getLedgerIdGenerator();
ledgerIdGenerator.generateLedgerId(new GenericCallback<Long>() {
@Override
public void operationComplete(int rc, Long ledgerId) {
if (BKException.Code.OK != rc) {
createComplete(rc, null);
return;
}
LedgerCreateOp.this.ledgerId = ledgerId;
// create a ledger with metadata
bk.getLedgerManager().createLedgerMetadata(ledgerId, metadata, LedgerCreateOp.this);
}
});
}
Aggregations