eventBuffer1,
null,
false));
eventBuffer1.endEvents(2);
DbusEventIterator it1 = eventBuffer1.acquireIterator("it1");
assertTrue("buffer has event", it1.hasNext());
DbusEvent testEvent = it1.next();
assertEquals("key correct", 1L, testEvent.key());
assertEquals("sequence correct", 2L, testEvent.sequence());
assertEquals("partitionId correct", 3, testEvent.logicalPartitionId());
assertEquals("timestamp correct", 4L, testEvent.timestampInNanos());
assertEquals("srcId correct", 5, testEvent.srcId());
assertEquals("schemaId correct", new String(schemaId), new String(testEvent.schemaId()));
assertEquals("value correct", valueStr, Utils.byteBufferToString(testEvent.value()));
assertEquals("Get DbusEventKey", 1L, ((DbusEventInternalReadable)testEvent).getDbusEventKey().getLongKey().longValue());
//test JSON
jsonOut = new ByteArrayOutputStream();
jsonOutChannel = Channels.newChannel(jsonOut);
event1.writeTo(jsonOutChannel, Encoding.JSON);
jsonBytes = jsonOut.toByteArray();
jsonString = new String(jsonBytes);
jsonMap = mapper.readValue(jsonString, new TypeReference<Map<String, Object>>(){});
assertEquals("key correct", 1L, ((Number)jsonMap.get("key")).longValue());
assertEquals("sequence correct", 2L, ((Number)jsonMap.get("sequence")).longValue());
assertEquals("logicalPartitionId correct", 3, ((Number)jsonMap.get("logicalPartitionId")).shortValue());
assertEquals("timestampInNanos correct", 4L, ((Number)jsonMap.get("timestampInNanos")).longValue());
assertEquals("srcId correct", 5, ((Number)jsonMap.get("srcId")).longValue());
assertEquals("schemaId correct", Base64.encodeBytes(schemaId), jsonMap.get("schemaId"));
assertEquals("valueEnc correct", Encoding.JSON.toString(), jsonMap.get("valueEnc"));
assertEquals("value correct", Base64.encodeBytes(valueStr.getBytes(Charset.defaultCharset())), jsonMap.get("value"));
assertTrue("buffer has event", it1.hasNext());
testEvent = it1.next();
assertTrue("end of window", testEvent.isEndOfPeriodMarker());
DbusEventBuffer eventBuffer2 =
new DbusEventBuffer(getConfig(100000, DbusEventBuffer.Config.DEFAULT_INDIVIDUAL_BUFFER_SIZE, 10000, 1000,
AllocationPolicy.HEAP_MEMORY, QueuePolicy.OVERWRITE_ON_WRITE));
eventBuffer2.startEvents();
assertTrue("json deserialization", (DbusEventSerializable.appendToEventBuffer(jsonString, eventBuffer2, null, false) > 0));
eventBuffer2.endEvents(2);
DbusEventIterator it2 = eventBuffer2.acquireIterator("it2");
assertTrue("buffer has event", it2.hasNext());
testEvent = it2.next();
assertEquals("key correct", 1L, testEvent.key());
assertEquals("partitionId correct", 3, testEvent.logicalPartitionId());
assertEquals("timestamp correct", 4L, testEvent.timestampInNanos());
assertEquals("srcId correct", 5, testEvent.srcId());
assertEquals("schemaId correct", new String(schemaId), new String(testEvent.schemaId()));
assertEquals("value correct", valueStr, Utils.byteBufferToString(testEvent.value()));
assertEquals("Get DbusEventKey", 1L, ((DbusEventInternalReadable)testEvent).getDbusEventKey().getLongKey().longValue());
assertTrue("buffer has event", it2.hasNext());
testEvent = it2.next();
assertTrue("end of window", testEvent.isEndOfPeriodMarker());
}