Search in sources :

Example 1 with SessionState

use of com.couchbase.client.dcp.state.SessionState in project components by Talend.

the class CouchbaseStreamingConnectionTest method testStartStreaming.

@Test
public void testStartStreaming() throws InterruptedException {
    Mockito.when(client.initializeState(StreamFrom.BEGINNING, StreamTo.NOW)).thenReturn(Completable.complete());
    Mockito.when(client.startStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
    SessionState sessionState = Mockito.mock(SessionState.class);
    Mockito.when(sessionState.isAtEnd()).thenReturn(false, false, true);
    Mockito.when(client.sessionState()).thenReturn(sessionState);
    BlockingQueue<ByteBuf> resultsQueue = new ArrayBlockingQueue<>(3);
    streamingConnection.startStreaming(resultsQueue);
    Assert.assertTrue(streamingConnection.isStreaming());
    Thread.sleep(2000);
    Mockito.verify(client, Mockito.times(3)).sessionState();
}
Also used : SessionState(com.couchbase.client.dcp.state.SessionState) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ByteBuf(com.couchbase.client.deps.io.netty.buffer.ByteBuf) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with SessionState

use of com.couchbase.client.dcp.state.SessionState in project components by Talend.

the class CouchbaseStreamingConnectionTest method testStartStopStreaming.

@Test
public void testStartStopStreaming() throws InterruptedException {
    Mockito.when(client.initializeState(StreamFrom.BEGINNING, StreamTo.NOW)).thenReturn(Completable.complete());
    Mockito.when(client.startStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
    Mockito.when(client.stopStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
    SessionState sessionState = Mockito.mock(SessionState.class);
    Mockito.when(sessionState.isAtEnd()).thenReturn(false, true);
    Mockito.when(client.sessionState()).thenReturn(sessionState);
    BlockingQueue<ByteBuf> resultsQueue = new ArrayBlockingQueue<>(4);
    resultsQueue.put(Mockito.mock(ByteBuf.class));
    resultsQueue.put(Mockito.mock(ByteBuf.class));
    resultsQueue.put(Mockito.mock(ByteBuf.class));
    resultsQueue.put(Mockito.mock(ByteBuf.class));
    Mockito.when(client.disconnect()).thenReturn(Completable.complete());
    streamingConnection.startStreaming(resultsQueue);
    streamingConnection.stopStreaming();
    Thread.sleep(1500);
    Mockito.verify(client, Mockito.times(2)).sessionState();
    Mockito.verify(client, Mockito.times(1)).disconnect();
}
Also used : SessionState(com.couchbase.client.dcp.state.SessionState) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ByteBuf(com.couchbase.client.deps.io.netty.buffer.ByteBuf) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SessionState (com.couchbase.client.dcp.state.SessionState)2 ByteBuf (com.couchbase.client.deps.io.netty.buffer.ByteBuf)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2