Package org.apache.bookkeeper.client

Examples of org.apache.bookkeeper.client.LedgerEntry


                   
                    long readLastConfirmed = lhOpen.readLastConfirmed();
                    assertTrue(readLastConfirmed != 0);
                    Enumeration<LedgerEntry> readEntry = lhOpen.readEntries(toRead, toRead);
                    assertTrue("Enumeration of ledger entries has no element", readEntry.hasMoreElements() == true);
                    LedgerEntry e = readEntry.nextElement();
                    assertEquals(toRead, e.getEntryId());
                    Assert.assertArrayEquals(entries.get(toRead), e.getEntry());
                    // should not written to a read only ledger
                    try {
                        lhOpen.addEntry(entry.array());
                        fail("Should have thrown an exception here");
                    } catch (BKException.BKIllegalOpException bkioe) {
View Full Code Here


            }
            while (start < numMsgs) {
                Enumeration<LedgerEntry> seq = lhs[j].readEntries(start, end);
                assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements() == true);
                while (seq.hasMoreElements()) {
                    LedgerEntry e = seq.nextElement();
                    assertEquals(entryId, e.getEntryId());

                    StringBuilder sb = new StringBuilder();
                    sb.append(ledgerIds[j]).append('-').append(entryId).append('-')
                      .append(msg);
                    Assert.assertArrayEquals(sb.toString().getBytes(), e.getEntry());
                    entryId++;
                }
                assertEquals(entryId - 1, end);
                start = end + 1;
                read = Math.min(numToRead, numMsgs - start);
View Full Code Here

        Enumeration<LedgerEntry> seq = wlh.readEntries(0, numMsgs - 1);
        assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements() == true);
        int entryId = 0;
        while (seq.hasMoreElements()) {
            LedgerEntry e = seq.nextElement();
            assertEquals(entryId, e.getEntryId());

            Assert.assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
            ++entryId;
        }
        assertEquals(entryId, numMsgs);
    }
View Full Code Here

        numMsgs += 3;
        Enumeration<LedgerEntry> seq = lh2.readEntries(0, numMsgs - 1);
        assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements() == true);
        int entryId = 0;
        while (seq.hasMoreElements()) {
            LedgerEntry e = seq.nextElement();
            assertEquals(entryId, e.getEntryId());

            Assert.assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
            ++entryId;
        }
        assertEquals(entryId, numMsgs);
    }
View Full Code Here

            while (startSeqId <= tEndSeqId) {
                correctedEndSeqId = Math.min(startSeqId + NUM_MESSAGES_TO_PRINT - 1, tEndSeqId);
               
                try {
                    Enumeration<LedgerEntry> seq = lh.readEntries(startSeqId - ledger.startSeqIdIncluded, correctedEndSeqId - ledger.startSeqIdIncluded);
                    LedgerEntry entry = null;
                    while (seq.hasMoreElements()) {
                        entry = seq.nextElement();
                        Message message;
                        try {
                            message = Message.parseFrom(entry.getEntryInputStream());
                        } catch (IOException e) {
                            System.out.println("WARN: Unreadable message found\n");
                            expectedEntryId++;
                            continue;
                        }
                        if (expectedEntryId != entry.getEntryId()
                            || (message.getMsgId().getLocalComponent() - ledger.startSeqIdIncluded) != expectedEntryId) {
                            throw new IOException("ERROR: Message ids are out of order : expected entry id " + expectedEntryId
                                                + ", current entry id " + entry.getEntryId() + ", msg seq id " + message.getMsgId().getLocalComponent());
                        }
                        expectedEntryId++;
                        formatMessage(message);

                    }
View Full Code Here

               
                try {
                    Enumeration<LedgerEntry> seq =
                        lh.readEntries(startSeqId - ledger.getStartSeqIdIncluded(),
                                       correctedEndSeqId - ledger.getStartSeqIdIncluded());
                    LedgerEntry entry = null;
                    while (seq.hasMoreElements()) {
                        entry = seq.nextElement();
                        Message message;
                        try {
                            message = Message.parseFrom(entry.getEntryInputStream());
                        } catch (IOException e) {
                            System.out.println("WARN: Unreadable message found\n");
                            expectedEntryId++;
                            continue;
                        }
                        if (expectedEntryId != entry.getEntryId()
                            || (message.getMsgId().getLocalComponent() - ledger.getStartSeqIdIncluded()) != expectedEntryId) {
                            throw new IOException("ERROR: Message ids are out of order : expected entry id " + expectedEntryId
                                                + ", current entry id " + entry.getEntryId() + ", msg seq id " + message.getMsgId().getLocalComponent());
                        }
                        expectedEntryId++;
                        formatMessage(message);

                    }
View Full Code Here

            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
            lastEntry = last;
        }
        LedgerEntry le = ledgerSeq.nextElement();
        bbytes = le.getEntry();
        bytebuff = ByteBuffer.wrap(bbytes);
        return true;
    }
View Full Code Here

        // Now kill the other bookie and read entries from the readonly bookie
        killBookie(0);

        Enumeration<LedgerEntry> readEntries = ledger.readEntries(0, 9);
        while (readEntries.hasMoreElements()) {
            LedgerEntry entry = readEntries.nextElement();
            assertEquals("Entry should contain correct data", "data",
                    new String(entry.getEntry()));
        }
    }
View Full Code Here

            }
            while (start < numMsgs) {
                Enumeration<LedgerEntry> seq = lhs[j].readEntries(start, end);
                assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements() == true);
                while (seq.hasMoreElements()) {
                    LedgerEntry e = seq.nextElement();
                    assertEquals(entryId, e.getEntryId());

                    StringBuilder sb = new StringBuilder();
                    sb.append(ledgerIds[j]).append('-').append(entryId).append('-')
                      .append(msg);
                    Assert.assertArrayEquals(sb.toString().getBytes(), e.getEntry());
                    entryId++;
                }
                assertEquals(entryId - 1, end);
                start = end + 1;
                read = Math.min(numToRead, numMsgs - start);
View Full Code Here

                    // no recovery opened ledger 's last confirmed entry id is less than written
                    // and it just can read until (i-1)
                    int toRead = i - 1;
                    Enumeration<LedgerEntry> readEntry = lhOpen.readEntries(toRead, toRead);
                    assertTrue("Enumeration of ledger entries has no element", readEntry.hasMoreElements() == true);
                    LedgerEntry e = readEntry.nextElement();
                    assertEquals(toRead, e.getEntryId());
                    Assert.assertArrayEquals(entries.get(toRead), e.getEntry());
                    // should not written to a read only ledger
                    try {
                        lhOpen.addEntry(entry.array());
                        fail("Should have thrown an exception here");
                    } catch (BKException.BKIllegalOpException bkioe) {
View Full Code Here

TOP

Related Classes of org.apache.bookkeeper.client.LedgerEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.