@Test public void testBoolean() { Buffer buffer = new FixedBuffer(16); buffer.put(true); buffer.put(false); Buffer read = new FixedBuffer(buffer.getBuffer()); boolean b = read.readBoolean(); Assert.assertEquals(true, b); boolean c = read.readBoolean(); Assert.assertEquals(false, c); }
protected void updateRecord(T record, PersistenceWindow window) { int id = record.getId(); Buffer buffer = window.getOffsettedBuffer(id); if (record.inUse()) { buffer.put(Record.IN_USE.byteValue()); writeRecord(record, buffer); } else { buffer.put(Record.NOT_IN_USE.byteValue()); if (!isInRecoveryMode()) { freeId(id); } } }
@Test public void testGetBuffer() throws Exception { Buffer buffer = new FixedBuffer(4); buffer.put(1); Assert.assertEquals(buffer.getOffset(), 4); Assert.assertEquals(buffer.getBuffer().length, 4); }
private void checkUnsignedByte(int value) { Buffer buffer = new FixedBuffer(1024); buffer.put((byte) value); byte[] buffer1 = buffer.getBuffer(); Buffer reader = new FixedBuffer(buffer1); int i = reader.readUnsignedByte(); Assert.assertEquals(value, i); }
private void setRecord(long id, long value) { PersistenceWindow window = acquireWindow(id, OperationType.WRITE); try { Buffer buffer = window.getOffsettedBuffer(id); buffer.put(Record.IN_USE.byteValue()).putLong(value); registerIdFromUpdateRecord(id); } finally { releaseWindow(window); } }
@Test public void testSliceGetBuffer() throws Exception { Buffer buffer = new FixedBuffer(5); buffer.put(1); Assert.assertEquals(buffer.getOffset(), 4); Assert.assertEquals(buffer.getBuffer().length, 4); byte[] buffer1 = buffer.getBuffer(); byte[] buffer2 = buffer.getBuffer(); Assert.assertTrue(buffer1 != buffer2); }
private void updateRecord(PropertyRecord record, PersistenceWindow window) { long id = record.getId(); registerIdFromUpdateRecord(id); Buffer buffer = window.getOffsettedBuffer(id); if (record.inUse()) { // Set up the record header short prevModifier = record.getPrevProp() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (short) ((record.getPrevProp() & 0xF00000000L) >> 28); short nextModifier = record.getNextProp() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (short) ((record.getNextProp() & 0xF00000000L) >> 32); byte modifiers = (byte) (prevModifier | nextModifier); /* * [pppp,nnnn] previous, next high bits */ buffer.put(modifiers); buffer.putInt((int) record.getPrevProp()).putInt((int) record.getNextProp()); // Then go through the blocks int longsAppended = 0; // For marking the end of blocks for (PropertyBlock block : record.getPropertyBlocks()) { long[] propBlockValues = block.getValueBlocks(); for (long propBlockValue : propBlockValues) { buffer.putLong(propBlockValue); } longsAppended += propBlockValues.length; /* * For each block we need to update its dynamic record chain if * it is just created. Deleted dynamic records are in the property * record and dynamic records are never modified. Also, they are * assigned as a whole, so just checking the first should be enough. */ if (!block.isLight() && block.getValueRecords().get(0).isCreated()) { updateDynamicRecords(block.getValueRecords()); } } if (longsAppended < PropertyType.getPayloadSizeLongs()) { buffer.putLong(0); } } else { if (!isInRecoveryMode()) { freeId(id); } // skip over the record header, nothing useful there buffer.setOffset(buffer.getOffset() + 9); buffer.putLong(0); } updateDynamicRecords(record.getDeletedRecords()); }
@Test public void readPadStringAndRightTrim() { String testString = StringUtils.repeat('a', 10); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadString(testString, 20); writeBuffer.put(255); Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); String readPadString = readBuffer.readPadStringAndRightTrim(20); Assert.assertEquals(testString, readPadString); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
@Test public void readPadBytes() { byte[] bytes = new byte[10]; random.nextBytes(bytes); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadBytes(bytes, 20); writeBuffer.put(255); Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); byte[] readPadBytes = readBuffer.readPadBytes(20); Assert.assertArrayEquals(bytes, Arrays.copyOf(readPadBytes, 10)); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
protected ColumnFamily getColumnFamily() throws IOException { ColumnFamily previous = buffer.get(currentKey); // If the CF already exist in memory, we'll just continue adding to it if (previous == null) { previous = createColumnFamily(); buffer.put(currentKey, previous); // Since this new CF will be written by the next sync(), count its header. And a CF header // on disk is: // - the row key: 2 bytes size + key size bytes // - the row level deletion infos: 4 + 8 bytes currentSize += 14 + currentKey.getKey().remaining(); } return previous; }
public void test() throws Exception { Consumer consumer = new Consumer(buffer); Thread thread = new Thread(consumer); thread.start(); for (int i = 0; i < 1000; i++) { buffer.put(new Integer(i)); } thread.join(); for (int i = 0; i < consumer.taken.size(); i++) { Integer integer = (Integer) consumer.taken.get(i); assertEquals(i, integer.intValue()); } }
protected ColumnFamily getColumnFamily() { ColumnFamily previous = buffer.get(currentKey); // If the CF already exist in memory, we'll just continue adding to it if (previous == null) { previous = TreeMapBackedSortedColumns.factory.create(metadata); buffer.put(currentKey, previous); } else { // We will reuse a CF that we have counted already. But because it will be easier to add the // full size // of the CF in the next writeRow call than to find out the delta, we just remove the size // until that next call currentSize -= currentKey.key.remaining() + ColumnFamily.serializer.serializedSize(previous, MessagingService.current_version) * 1.2; } return previous; }
private void testPutPrefixedBytes(String test, int expected) { Buffer buffer = new FixedBuffer(1024); if (test != null) { buffer.putPrefixedBytes(test.getBytes(UTF8_CHARSET)); } else { buffer.putPrefixedString(null); } buffer.put(expected); byte[] buffer1 = buffer.getBuffer(); Buffer actual = new FixedBuffer(buffer1); String s = actual.readPrefixedString(); Assert.assertEquals(test, s); int i = actual.readInt(); Assert.assertEquals(expected, i); }
public void prep(Buffer buf) { Colors p = buf.get(colors); if (p != null) buf.put(colors, p.combine(this)); else buf.put(colors, this); }
public void prep(Buffer buf) { buf.put(slot, this); }
public void prep(Buffer buf) { buf.put(depthoffset, this); }
public void prep(Buffer buf) { buf.put(adhocg, this); }
public void prep(Buffer buf) { buf.put(fog, this); }
public void prep(Buffer buf) { buf.put(pointsize, this); }
public void prep(Buffer buf) { buf.put(color, this); }
public void prep(Buffer buf) { buf.put(proj2d, this); }
public void prep(Buffer buf) { buf.put(coverage, this); }
public void run() { char chars[] = line.toCharArray(); for (char c : chars) { buffer.put(c); } }