use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResult in project engineblock by engineblock.
the class ByteTrackerExtentTest method testOrdered4.
@Test
public void testOrdered4() {
ByteTrackerExtent bt4 = new ByteTrackerExtent(33, 37);
bt4.markResult(36L, 3);
bt4.markResult(33L, 0);
bt4.markResult(35L, 2);
assertThat(bt4.getMarkerData()[3]).isEqualTo((byte) 3);
assertThat(bt4.getMarkerData()[0]).isEqualTo((byte) 0);
assertThat(bt4.getMarkerData()[2]).isEqualTo((byte) 2);
assertThat(bt4.isFullyFilled()).isFalse();
bt4.markResult(34L, 1);
assertThat(bt4.getMarkerData()[1]).isEqualTo((byte) 1);
assertThat(bt4.isFullyFilled()).isTrue();
List<CycleResult> cycleResults = new ArrayList<>();
List<CycleResultsSegment> segments = StreamSupport.stream(bt4.spliterator(), false).collect(Collectors.toList());
for (CycleResultsSegment segment : segments) {
segment.forEach(cycleResults::add);
}
long[] cycles = cycleResults.stream().mapToLong(CycleResult::getCycle).toArray();
int[] results = cycleResults.stream().mapToInt(CycleResult::getResult).toArray();
assertThat(cycles).containsExactly(33L, 34L, 35L, 36L);
assertThat(results).containsExactly(0, 1, 2, 3);
// CycleResultsSegment seg1 = iterator;
// assertThat(seg1.cycle).isEqualTo(33);
// assertThat(seg1.codes.length).isEqualTo(2);
// assertThat(seg1.codes[0]).isEqualTo((byte)0);
// assertThat(bt4.isFullyServed()).isFalse();
// CycleResultsIntervalSegment seg2 = bt4.getCycleResultsSegment(2);
// assertThat(bt4.isFullyServed()).isTrue();
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResult in project engineblock by engineblock.
the class CycleResultsRLEBufferReadableTest method testRLESingle3.
@Test
public void testRLESingle3() {
ByteBuffer bb = ByteBuffer.allocate(3 * (Long.BYTES + Long.BYTES + Byte.BYTES));
bb.putLong(31L).putLong(32L).put((byte) 127);
bb.putLong(41L).putLong(43L).put((byte) 53);
bb.putLong(132L).putLong(135L).put((byte) 27);
bb.flip();
CycleResultsRLEBufferReadable crb = new CycleResultsRLEBufferReadable(bb);
ArrayList<CycleResult> cycles = new ArrayList<>();
crb.iterator().forEachRemaining(s -> s.forEach(cycles::add));
long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
assertThat(cycleValues).containsExactly(31L, 41L, 42L, 132L, 133L, 134L);
assertThat(resultValues).containsExactly(127, 53, 53, 27, 27, 27);
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResult in project engineblock by engineblock.
the class CycleResultsRLEBufferTargetTest method testBasicRLEncoding.
@Test
public void testBasicRLEncoding() {
CycleResultsRLEBufferTarget tb = new CycleResultsRLEBufferTarget(1024);
assertThat(tb.getRawBufferCapacity()).isEqualTo(17408);
tb.onCycleResult(0L, 0);
tb.onCycleResult(1L, 1);
CycleResultsRLEBufferReadable r = tb.toSegmentsReadable();
ArrayList<CycleResult> cycles = new ArrayList<>();
Iterable<CycleResult> ci = r.getCycleResultIterable();
Iterator<CycleResult> cit = ci.iterator();
while (cit.hasNext()) {
cycles.add(cit.next());
}
long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
assertThat(cycleValues).containsExactly(0L, 1L);
int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
assertThat(resultValues).containsExactly(0, 1);
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResult in project engineblock by engineblock.
the class CycleResultsRLEBufferTargetTest method testGappedIntervalRLEEncoding.
public void testGappedIntervalRLEEncoding() {
CycleResultsRLEBufferTarget tb = new CycleResultsRLEBufferTarget(100000);
assertThat(tb.getRawBufferCapacity()).isEqualTo(1700000);
tb.onCycleResult(0L, 0);
tb.onCycleResult(13L, 1);
tb.onCycleResult(14L, 1);
tb.onCycleResult(15L, 1);
tb.onCycleResult(28L, 2);
tb.onCycleResult(29L, 2);
tb.onCycleResult(100L, 5);
tb.onCycleResult(101L, 6);
tb.onCycleResult(102L, 7);
CycleResultsRLEBufferReadable r = tb.toSegmentsReadable();
ArrayList<CycleResult> cycles = new ArrayList<>();
r.getCycleResultIterable().iterator().forEachRemaining(cycles::add);
long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
assertThat(cycleValues).containsExactly(0L, 13L, 14L, 15L, 28L, 29L, 100L, 101L, 102L);
int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
assertThat(resultValues).containsExactly(0, 1, 1, 1, 2, 2, 5, 6, 7);
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResult in project engineblock by engineblock.
the class ResultFilteringSieveTest method testPredicateConversions.
public void testPredicateConversions() {
SimpleCycleResult c1 = new SimpleCycleResult(1, 1);
SimpleCycleResult c2 = new SimpleCycleResult(2, 2);
SimpleCycleResult c3 = new SimpleCycleResult(3, 3);
SimpleCycleResult c4 = new SimpleCycleResult(4, 4);
SimpleCycleResult c5 = new SimpleCycleResult(5, 5);
SimpleCycleResult c6 = new SimpleCycleResult(6, 6);
SimpleCycleResult c7 = new SimpleCycleResult(7, 7);
List<CycleResult> results = new ArrayList<CycleResult>() {
{
add(c1);
add(c2);
add(c3);
add(c4);
add(c5);
add(c6);
add(c7);
}
};
Predicate<ResultReadable> includer = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toInclusivePredicate();
List<CycleResult> included = results.stream().filter(includer).collect(Collectors.toList());
assertThat(included).containsExactly(c1, c2, c3, c5, c6, c7);
Predicate<ResultReadable> excluder = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toExclusivePredicate();
List<CycleResult> excluded = results.stream().filter(excluder).collect(Collectors.toList());
assertThat(excluded).containsExactly(c3);
}
Aggregations