Search in sources :

Example 1 with CycleArray

use of io.engineblock.activityapi.cyclelog.buffers.cycles.CycleArray in project engineblock by engineblock.

the class CycleArrayBufferTest method testBasicBuffering.

@Test
public void testBasicBuffering() {
    CycleArrayBuffer b = new CycleArrayBuffer(3);
    assertThat(b.remaining()).isEqualTo(3);
    b.append(4L);
    assertThat(b.remaining()).isEqualTo(2);
    b.append(7L);
    assertThat(b.remaining()).isEqualTo(1);
    b.append(2L);
    assertThat(b.remaining()).isEqualTo(0);
    CycleArray a = b.getCycleArray();
    CycleSegment is = a.getInputSegment(3);
    long[] longs = is.nextCycles(3);
    assertThat(longs).containsExactly(4L, 7L, 2L);
    assertThat(a.getInputSegment(1)).isNull();
}
Also used : CycleArray(io.engineblock.activityapi.cyclelog.buffers.cycles.CycleArray) CycleSegment(io.engineblock.activityapi.cyclelog.buffers.cycles.CycleSegment) Test(org.testng.annotations.Test)

Example 2 with CycleArray

use of io.engineblock.activityapi.cyclelog.buffers.cycles.CycleArray in project engineblock by engineblock.

the class CycleArrayTest method testBasicArray.

@Test
public void testBasicArray() {
    CycleArray a1 = new CycleArray(2, 3, 9);
    CycleSegment s1 = a1.getInputSegment(1);
    assertThat(s1).isNotNull();
    assertThat(s1.isExhausted()).isFalse();
    long v1 = s1.nextCycle();
    assertThat(v1).isEqualTo(2L);
    assertThat(s1.isExhausted()).isTrue();
    long v2 = s1.nextCycle();
    assertThat(v2).isLessThan(0);
    CycleSegment s2 = a1.getInputSegment(2);
    assertThat(s2).isNotNull();
    assertThat(s2.isExhausted()).isFalse();
    long v3 = s2.nextCycle();
    assertThat(v3).isEqualTo(3L);
    assertThat(s2.isExhausted()).isFalse();
    long v4 = s2.nextCycle();
    assertThat(v4).isEqualTo(9L);
    assertThat(s2.isExhausted()).isTrue();
    long v5 = s2.nextCycle();
    assertThat(v5).isLessThan(0);
    CycleSegment s3 = a1.getInputSegment(1);
    assertThat(s3).isNull();
}
Also used : CycleArray(io.engineblock.activityapi.cyclelog.buffers.cycles.CycleArray) CycleSegment(io.engineblock.activityapi.cyclelog.buffers.cycles.CycleSegment) Test(org.testng.annotations.Test)

Aggregations

CycleArray (io.engineblock.activityapi.cyclelog.buffers.cycles.CycleArray)2 CycleSegment (io.engineblock.activityapi.cyclelog.buffers.cycles.CycleSegment)2 Test (org.testng.annotations.Test)2