Search in sources :

Example 1 with CycleResultsRLEBufferTarget

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget in project engineblock by engineblock.

the class CycleResultsRLEBufferReadableTest method testMultipleRanges.

@Test
public void testMultipleRanges() {
    CycleResultsRLEBufferTarget t = new CycleResultsRLEBufferTarget(1000);
    t.onCycleResult(1L, 1);
    t.onCycleResult(2L, 1);
    t.onCycleResult(10L, 2);
    t.onCycleResult(11L, 2);
    t.onCycleResult(13L, 2);
    t.onCycleResult(7L, 7);
    // CycleResultsRLEBufferReadable cr = t.toSegmentsReadable();
    long[] cycleValues = StreamSupport.stream(t.toSegmentsReadable().spliterator(), false).flatMap(r -> StreamSupport.stream(r.spliterator(), false)).mapToLong(CycleResult::getCycle).toArray();
    int[] resultValues = StreamSupport.stream(t.toSegmentsReadable().spliterator(), false).flatMap(s -> StreamSupport.stream(s.spliterator(), false)).mapToInt(CycleResult::getResult).toArray();
    assertThat(cycleValues).containsExactly(1L, 2L, 10L, 11L, 13L, 7L);
    assertThat(resultValues).containsExactly(1, 1, 2, 2, 2, 7);
}
Also used : CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) Test(org.testng.annotations.Test)

Example 2 with CycleResultsRLEBufferTarget

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget in project engineblock by engineblock.

the class CycleResultsRLEBufferReadableTest method testGetCycleResultsSegment.

@Test
public void testGetCycleResultsSegment() {
    CycleResultsRLEBufferTarget t = new CycleResultsRLEBufferTarget(1000);
    t.onCycleResult(1L, 1);
    t.onCycleResult(2L, 1);
    t.onCycleResult(10L, 2);
    t.onCycleResult(11L, 2);
    t.onCycleResult(13L, 2);
    t.onCycleResult(7L, 7);
    CycleResultsRLEBufferReadable readable = t.toSegmentsReadable();
    CycleResultsSegment s1 = readable.iterator().next();
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) CycleResultsSegment(io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment) Test(org.testng.annotations.Test)

Example 3 with CycleResultsRLEBufferTarget

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget 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);
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) ArrayList(java.util.ArrayList) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult) Test(org.testng.annotations.Test)

Example 4 with CycleResultsRLEBufferTarget

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget in project engineblock by engineblock.

the class CycleResultsRLEBufferTargetTest method testResize.

@Test
public void testResize() {
    CycleResultsRLEBufferTarget tb = new CycleResultsRLEBufferTarget(3);
    assertThat(tb.getRawBufferCapacity()).isEqualTo(51);
    tb.onCycleResult(0L, 0);
    tb.onCycleResult(13L, 1);
    tb.onCycleResult(14L, 2);
    tb.onCycleResult(15L, 3);
    assertThat(tb.getRecordCapacity()).isEqualTo(3);
    tb.onCycleResult(19L, 19);
    assertThat(tb.getRecordCapacity()).isEqualTo(6);
    tb.onCycleResult(20L, 10);
    tb.onCycleResult(21L, 21);
    tb.onCycleResult(22L, 22);
    assertThat(tb.getRecordCapacity()).isEqualTo(12);
}
Also used : CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) Test(org.testng.annotations.Test)

Example 5 with CycleResultsRLEBufferTarget

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget 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);
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) ArrayList(java.util.ArrayList) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)

Aggregations

CycleResultsRLEBufferTarget (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget)7 Test (org.testng.annotations.Test)5 CycleResultsRLEBufferReadable (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable)4 CycleResult (io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)3 CycleResultsSegment (io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment)2 ArrayList (java.util.ArrayList)2