Search in sources :

Example 46 with LedgerHandle

use of org.apache.bookkeeper.client.LedgerHandle in project pulsar by yahoo.

the class EntryCacheTest method testRead.

@Test(timeOut = 5000)
void testRead() throws Exception {
    LedgerHandle lh = getLedgerHandle();
    when(lh.getId()).thenReturn((long) 0);
    EntryCacheManager cacheManager = factory.getEntryCacheManager();
    EntryCache entryCache = cacheManager.getEntryCache(ml);
    byte[] data = new byte[10];
    for (int i = 0; i < 10; i++) {
        entryCache.insert(new EntryImpl(0, i, data));
    }
    final CountDownLatch counter = new CountDownLatch(1);
    entryCache.asyncReadEntry(lh, 0, 9, false, new ReadEntriesCallback() {

        public void readEntriesComplete(List<Entry> entries, Object ctx) {
            assertEquals(entries.size(), 10);
            entries.forEach(e -> e.release());
            counter.countDown();
        }

        public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
            Assert.fail("should not have failed");
        }
    }, null);
    counter.await();
    // Verify no entries were read from bookkeeper
    verify(lh, never()).asyncReadEntries(anyLong(), anyLong(), any(ReadCallback.class), any());
}
Also used : ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) MockedBookKeeperTestCase(org.apache.bookkeeper.test.MockedBookKeeperTestCase) Entry(org.apache.bookkeeper.mledger.Entry) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Unpooled(io.netty.buffer.Unpooled) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Vector(java.util.Vector) Assert(org.testng.Assert) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Matchers.anyLong(org.mockito.Matchers.anyLong) Mockito.doReturn(org.mockito.Mockito.doReturn) Method(java.lang.reflect.Method) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.when(org.mockito.Mockito.when) BKException(org.apache.bookkeeper.client.BKException) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) List(java.util.List) ReadCallback(org.apache.bookkeeper.client.AsyncCallback.ReadCallback) ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) Mockito.mock(org.mockito.Mockito.mock) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) CountDownLatch(java.util.concurrent.CountDownLatch) Entry(org.apache.bookkeeper.mledger.Entry) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ReadCallback(org.apache.bookkeeper.client.AsyncCallback.ReadCallback) Test(org.testng.annotations.Test)

Aggregations

LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)46 Test (org.junit.Test)19 ZKTransaction (com.twitter.distributedlog.zk.ZKTransaction)13 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)12 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 IOException (java.io.IOException)8 Entry (org.apache.bookkeeper.mledger.Entry)8 BKException (org.apache.bookkeeper.client.BKException)7 ReadEntriesCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback)7 Test (org.testng.annotations.Test)7 List (java.util.List)6 BookKeeper (org.apache.bookkeeper.client.BookKeeper)6 ZKDistributedLock (com.twitter.distributedlog.lock.ZKDistributedLock)5 Future (com.twitter.util.Future)5 ArrayList (java.util.ArrayList)5 ZKException (com.twitter.distributedlog.exceptions.ZKException)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Lists (com.google.common.collect.Lists)3 BKTransmitException (com.twitter.distributedlog.exceptions.BKTransmitException)3