Search in sources :

Example 6 with CycleResultsRLEBufferTarget

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

the class CycleLogOutput method onCycleResultSegment.

@Override
public void onCycleResultSegment(CycleResultsSegment segment) {
    for (CycleResult cycleResult : segment) {
        if (filter == null || filter.test(cycleResult)) {
            boolean buffered = targetBuffer.onCycleResult(cycleResult);
            if (!buffered) {
                flush();
                targetBuffer = new CycleResultsRLEBufferTarget(extentSizeInSpans);
                boolean bufferedAfterFlush = targetBuffer.onCycleResult(cycleResult);
                if (!bufferedAfterFlush) {
                    throw new RuntimeException("Failed to record result in new target buffer");
                }
            }
        }
    }
}
Also used : CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)

Example 7 with CycleResultsRLEBufferTarget

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

the class CycleResultsRLEBufferReadableTest method testIteratorExhausted.

@Test
public void testIteratorExhausted() {
    CycleResultsRLEBufferTarget t = new CycleResultsRLEBufferTarget(1000);
    t.onCycleResult(1L, 5);
    t.onCycleResult(2L, 6);
    t.onCycleResult(4L, 8);
    CycleResultsRLEBufferReadable cr = t.toSegmentsReadable();
    Iterator<CycleResultsSegment> iterator = cr.iterator();
    CycleResultsSegment s1 = iterator.next();
    assertThat(s1.getCount()).isEqualTo(1);
    CycleResultsSegment s2 = iterator.next();
    assertThat(s2.getCount()).isEqualTo(1);
    CycleResultsSegment s3 = iterator.next();
    assertThat(s3.getCount()).isEqualTo(1);
    assertThat(iterator.hasNext()).isFalse();
// long[] cycleValues = StreamSupport.stream(cr.spliterator(), false)
// .mapToLong(CycleResult::getCycle).toArray();
// int[] resultValues = StreamSupport.stream(cr.spliterator(), false)
// .mapToInt(CycleResult::getResult).toArray();
// 
// assertThat(cycleValues).containsExactly(1L, 2L, 4L);
// assertThat(resultValues).containsExactly(5, 6, 8);
// 
}
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)

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