use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method checkEntry.
private static void checkEntry(Entry e, Map<Integer, Long> entries) {
ReadBuffer rb = e.asReadBuffer();
int key = rb.getInt();
assertEquals(e.getValuePosition(), rb.getPosition());
assertTrue(e.hasValue());
long value = rb.getLong();
assertFalse(rb.hasRemaining());
assertEquals((long) entries.get(key), value);
rb = e.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
assertEquals(key, rb.getInt());
assertFalse(rb.hasRemaining());
rb = e.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
assertEquals(value, rb.getLong());
assertFalse(rb.hasRemaining());
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testInversion.
@Test
public void testInversion() {
WriteBuffer wb = new WriteByteBuffer(20);
wb.putInt(1).putInt(2).putInt(3).putInt(4);
Entry entry = new StaticArrayEntry(wb.getStaticBufferFlipBytes(4, 2 * 4), 3 * 4);
ReadBuffer rb = entry.asReadBuffer();
assertEquals(1, rb.getInt());
assertEquals(2, rb.subrange(4, true).getInt());
assertEquals(~2, rb.getInt());
assertEquals(3, rb.getInt());
assertEquals(4, rb.getInt());
rb.movePositionTo(entry.getValuePosition());
assertEquals(4, rb.getInt());
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testReadWrite.
@Test
public void testReadWrite() {
WriteBuffer b = new WriteByteBuffer(10);
for (int i = 1; i < 4; i++) b.putByte((byte) i);
for (int i = 1; i < 4; i++) b.putShort((short) i);
for (int i = 1; i < 4; i++) b.putInt(i);
for (int i = 1; i < 4; i++) b.putLong(i);
for (int i = 1; i < 4; i++) b.putFloat(i);
for (int i = 1; i < 4; i++) b.putDouble(i);
for (int i = 101; i < 104; i++) b.putChar((char) i);
ReadBuffer r = b.getStaticBuffer().asReadBuffer();
assertEquals(1, r.getByte());
assertArrayEquals(new byte[] { 2, 3 }, r.getBytes(2));
assertEquals(1, r.getShort());
assertArrayEquals(new short[] { 2, 3 }, r.getShorts(2));
assertEquals(1, r.getInt());
assertEquals(2, r.getInt());
assertArrayEquals(new int[] { 3 }, r.getInts(1));
assertEquals(1, r.getLong());
assertArrayEquals(new long[] { 2, 3 }, r.getLongs(2));
assertEquals(1.0, r.getFloat(), 0.00001);
assertArrayEquals(new float[] { 2.0f, 3.0f }, r.getFloats(2));
assertEquals(1, r.getDouble(), 0.0001);
assertArrayEquals(new double[] { 2.0, 3.0 }, r.getDoubles(2));
assertEquals((char) 101, r.getChar());
assertEquals((char) 102, r.getChar());
assertArrayEquals(new char[] { (char) 103 }, r.getChars(1));
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testArrayBuffer.
@Test
public void testArrayBuffer() {
WriteBuffer wb = new WriteByteBuffer(128);
wb.putInt(1).putInt(2).putInt(3).putInt(4);
int valuePos = wb.getPosition();
wb.putInt(5).putInt(6);
Entry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
assertEquals(4 * 4, entry.getValuePosition());
assertEquals(6 * 4, entry.length());
assertTrue(entry.hasValue());
for (int i = 1; i <= 6; i++) assertEquals(i, entry.getInt((i - 1) * 4));
ReadBuffer rb = entry.asReadBuffer();
for (int i = 1; i <= 6; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
assertNull(entry.getCache());
entry.setCache(cache);
assertEquals(cache, entry.getCache());
rb = entry.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
for (int i = 1; i <= 4; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
rb = entry.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
for (int i = 5; i <= 6; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class ManagementLogger method read.
@Override
public void read(Message message) {
ReadBuffer in = message.getContent().asReadBuffer();
String senderId = message.getSenderId();
Serializer serializer = graph.getDataSerializer();
MgmtLogType logType = serializer.readObjectNotNull(in, MgmtLogType.class);
Preconditions.checkNotNull(logType);
switch(logType) {
case CACHED_TYPE_EVICTION:
{
long evictionId = VariableLong.readPositive(in);
long numEvictions = VariableLong.readPositive(in);
for (int i = 0; i < numEvictions; i++) {
long typeId = VariableLong.readPositive(in);
schemaCache.expireSchemaElement(typeId);
for (JanusGraphTransaction tx : graph.getOpenTransactions()) {
tx.expireSchemaElement(typeId);
}
}
final GraphCacheEvictionAction action = serializer.readObjectNotNull(in, GraphCacheEvictionAction.class);
Preconditions.checkNotNull(action);
final Thread ack = new Thread(new SendAckOnTxClose(evictionId, senderId, graph.getOpenTransactions(), action, graph.getGraphName()));
ack.setDaemon(true);
ack.start();
break;
}
case CACHED_TYPE_EVICTION_ACK:
{
String receiverId = serializer.readObjectNotNull(in, String.class);
long evictionId = VariableLong.readPositive(in);
if (receiverId.equals(graph.getConfiguration().getUniqueGraphId())) {
// Acknowledgements targeted at this instance
EvictionTrigger evictTrigger = evictionTriggerMap.get(evictionId);
if (evictTrigger != null) {
evictTrigger.receivedAcknowledgement(senderId);
} else
log.error("Could not find eviction trigger for {} from {}", evictionId, senderId);
}
break;
}
default:
assert logType == MgmtLogType.CONFIG_MUTATION;
break;
}
}
Aggregations