Search in sources :

Example 1 with GetHeadRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest in project jackrabbit-oak by apache.

the class StandbyClient method getHead.

@Nullable
String getHead() throws InterruptedException {
    channel.writeAndFlush(new GetHeadRequest(clientId));
    GetHeadResponse response = headQueue.poll(readTimeoutMs, TimeUnit.MILLISECONDS);
    if (response == null) {
        return null;
    }
    return response.getHeadRecordId();
}
Also used : GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) GetHeadResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse) Nullable(javax.annotation.Nullable)

Example 2 with GetHeadRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest in project jackrabbit-oak by apache.

the class RequestObserverHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
    if (msg instanceof GetHeadRequest) {
        onGetHeadRequest((GetHeadRequest) msg, address);
    } else if (msg instanceof GetSegmentRequest) {
        onGetSegmentRequest((GetSegmentRequest) msg, address);
    } else if (msg instanceof GetBlobRequest) {
        onGetBlobRequest((GetBlobRequest) msg, address);
    }
    ctx.fireChannelRead(msg);
}
Also used : GetBlobRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest) GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) InetSocketAddress(java.net.InetSocketAddress) GetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest)

Example 3 with GetHeadRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest in project jackrabbit-oak by apache.

the class GetHeadRequestHandlerTest method successfulReadsShouldGenerateResponses.

@Test
public void successfulReadsShouldGenerateResponses() throws Exception {
    StandbyHeadReader reader = mock(StandbyHeadReader.class);
    when(reader.readHeadRecordId()).thenReturn("recordId");
    EmbeddedChannel channel = new EmbeddedChannel(new GetHeadRequestHandler(reader));
    channel.writeInbound(new GetHeadRequest("clientId"));
    GetHeadResponse response = (GetHeadResponse) channel.readOutbound();
    assertEquals("recordId", response.getHeadRecordId());
    assertEquals("clientId", response.getClientId());
}
Also used : GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) GetHeadResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse) Test(org.junit.Test)

Example 4 with GetHeadRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest in project jackrabbit-oak by apache.

the class GetHeadRequestHandlerTest method unsuccessfulReadsShouldBeDiscarded.

@Test
public void unsuccessfulReadsShouldBeDiscarded() throws Exception {
    StandbyHeadReader reader = mock(StandbyHeadReader.class);
    when(reader.readHeadRecordId()).thenReturn(null);
    EmbeddedChannel channel = new EmbeddedChannel(new GetHeadRequestHandler(reader));
    channel.writeInbound(new GetHeadRequest("clientId"));
    assertNull(channel.readOutbound());
}
Also used : GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Aggregations

GetHeadRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 GetHeadResponse (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 Nullable (javax.annotation.Nullable)1 GetBlobRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest)1 GetSegmentRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest)1