Example usage for io.netty.buffer ByteBuf writeLong

List of usage examples for io.netty.buffer ByteBuf writeLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeLong.

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

From source file:org.apache.bookkeeper.bookie.BookieJournalTest.java

License:Apache License

/**
 * Generate fence entry./*ww  w.  j  a v  a2s. c  om*/
 */
private ByteBuf generateFenceEntry(long ledgerId) {
    ByteBuf bb = Unpooled.buffer();
    bb.writeLong(ledgerId);
    bb.writeLong(Bookie.METAENTRY_ID_FENCE_KEY);
    return bb;
}

From source file:org.apache.bookkeeper.bookie.BookieJournalTest.java

License:Apache License

/**
 * Generate meta entry with given master key.
 *///  w w  w  .j  a  v a 2 s .  c  o  m
private ByteBuf generateMetaEntry(long ledgerId, byte[] masterKey) {
    ByteBuf bb = Unpooled.buffer();
    bb.writeLong(ledgerId);
    bb.writeLong(Bookie.METAENTRY_ID_LEDGER_KEY);
    bb.writeInt(masterKey.length);
    bb.writeBytes(masterKey);
    return bb;
}

From source file:org.apache.bookkeeper.bookie.BookieWriteToJournalTest.java

License:Apache License

private static ByteBuf buildEntry(long ledgerId, long entryId, long lastAddConfirmed) {
    final ByteBuf data = Unpooled.buffer();
    data.writeLong(ledgerId);
    data.writeLong(entryId);/*w ww .  j a v a 2  s  .co  m*/
    data.writeLong(lastAddConfirmed);
    return data;
}

From source file:org.apache.bookkeeper.bookie.CheckpointOnNewLedgersTest.java

License:Apache License

private static ByteBuf createByteBuf(long ledgerId, long entryId, int entrySize) {
    byte[] data = new byte[entrySize];
    ThreadLocalRandom.current().nextBytes(data);
    ByteBuf buffer = Unpooled.wrappedBuffer(data);
    buffer.writerIndex(0);//from  w ww  . ja va 2s  . co  m
    buffer.writeLong(ledgerId);
    buffer.writeLong(entryId);
    buffer.writeLong(entryId - 1); // lac
    buffer.writerIndex(entrySize);
    return buffer;
}

From source file:org.apache.bookkeeper.bookie.CompactionTest.java

License:Apache License

private ByteBuf genEntry(long ledger, long entry, int size) {
    ByteBuf bb = Unpooled.buffer(size);
    bb.writeLong(ledger);
    bb.writeLong(entry);//from   w  ww .  j a  v a  2s. com
    while (bb.isWritable()) {
        bb.writeByte((byte) 0xFF);
    }
    return bb;
}

From source file:org.apache.bookkeeper.bookie.EntryLogTest.java

License:Apache License

private static ByteBuf generateEntry(long ledger, long entry) {
    byte[] data = generateDataString(ledger, entry).getBytes();
    ByteBuf bb = Unpooled.buffer(8 + 8 + data.length);
    bb.writeLong(ledger);
    bb.writeLong(entry);//from   w w  w . j  a v  a  2s  .  co  m
    bb.writeBytes(data);
    return bb;
}

From source file:org.apache.bookkeeper.bookie.EntryLogTest.java

License:Apache License

private ByteBuf generateEntry(long ledger, long entry, int length) {
    ByteBuf bb = Unpooled.buffer(length);
    bb.writeLong(ledger);
    bb.writeLong(entry);/*  ww w .j  a va 2  s . co m*/
    byte[] randbyteArray = new byte[length - 8 - 8];
    rand.nextBytes(randbyteArray);
    bb.writeBytes(randbyteArray);
    return bb;
}

From source file:org.apache.bookkeeper.bookie.InterleavedLedgerStorageTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    File tmpDir = File.createTempFile("bkTest", ".dir");
    tmpDir.delete();//from   ww  w.j a  v  a  2  s  . c o  m
    tmpDir.mkdir();
    File curDir = Bookie.getCurrentDirectory(tmpDir);
    Bookie.checkDirectoryStructure(curDir);

    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(),
            new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));

    entryLogger = new TestableEntryLogger(conf, ledgerDirsManager, null, NullStatsLogger.INSTANCE);
    interleavedStorage.initializeWithEntryLogger(conf, null, ledgerDirsManager, ledgerDirsManager, null,
            checkpointSource, checkpointer, entryLogger, statsProvider.getStatsLogger(BOOKIE_SCOPE));

    // Insert some ledger & entries in the interleaved storage
    for (long entryId = 0; entryId < numWrites; entryId++) {
        for (long ledgerId = 0; ledgerId < numOfLedgers; ledgerId++) {
            if (entryId == 0) {
                interleavedStorage.setMasterKey(ledgerId, ("ledger-" + ledgerId).getBytes());
                interleavedStorage.setFenced(ledgerId);
            }
            ByteBuf entry = Unpooled.buffer(128);
            entry.writeLong(ledgerId);
            entry.writeLong(entryId * entriesPerWrite);
            entry.writeBytes(("entry-" + entryId).getBytes());

            interleavedStorage.addEntry(entry);
        }
    }
}

From source file:org.apache.bookkeeper.bookie.InterleavedLedgerStorageTest.java

License:Apache License

@Test
public void testGetListOfEntriesOfLedgerAfterFlush() throws IOException {
    interleavedStorage.flush();//  w w  w .j av a2 s  .c  om

    // Insert some more ledger & entries in the interleaved storage
    for (long entryId = numWrites; entryId < moreNumOfWrites; entryId++) {
        for (long ledgerId = 0; ledgerId < numOfLedgers; ledgerId++) {
            ByteBuf entry = Unpooled.buffer(128);
            entry.writeLong(ledgerId);
            entry.writeLong(entryId * entriesPerWrite);
            entry.writeBytes(("entry-" + entryId).getBytes());

            interleavedStorage.addEntry(entry);
        }
    }

    for (long ledgerId = 0; ledgerId < numOfLedgers; ledgerId++) {
        OfLong entriesOfLedger = interleavedStorage.getListOfEntriesOfLedger(ledgerId);
        ArrayList<Long> arrayList = new ArrayList<Long>();
        Consumer<Long> addMethod = arrayList::add;
        entriesOfLedger.forEachRemaining(addMethod);
        assertEquals("Number of entries", moreNumOfWrites, arrayList.size());
        assertTrue("Entries of Ledger", IntStream.range(0, arrayList.size()).allMatch(i -> {
            return arrayList.get(i).longValue() == (i * entriesPerWrite);
        }));
    }
}

From source file:org.apache.bookkeeper.bookie.LedgerCacheTest.java

License:Apache License

private ByteBuf generateEntry(long ledger, long entry) {
    byte[] data = ("ledger-" + ledger + "-" + entry).getBytes();
    ByteBuf bb = Unpooled.buffer(8 + 8 + data.length);
    bb.writeLong(ledger);
    bb.writeLong(entry);//from  ww  w . java2s .  com
    bb.writeBytes(data);
    return bb;
}