Search in sources :

Example 11 with KvStateID

use of org.apache.flink.queryablestate.KvStateID in project flink by apache.

the class KvStateServerHandlerTest method testQueryUnknownKvStateID.

/**
 * Tests the failure response with {@link UnknownKvStateIdException} as cause on queries for
 * unregistered KvStateIDs.
 */
@Test
public void testQueryUnknownKvStateID() throws Exception {
    KvStateRegistry registry = new KvStateRegistry();
    AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();
    MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
    KvStateServerHandler handler = new KvStateServerHandler(testServer, registry, serializer, stats);
    EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);
    long requestId = Integer.MAX_VALUE + 182828L;
    KvStateInternalRequest request = new KvStateInternalRequest(new KvStateID(), new byte[0]);
    ByteBuf serRequest = MessageSerializer.serializeRequest(channel.alloc(), requestId, request);
    // Write the request and wait for the response
    channel.writeInbound(serRequest);
    ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
    // skip frame length
    buf.skipBytes(4);
    // Verify the response
    assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf));
    RequestFailure response = MessageSerializer.deserializeRequestFailure(buf);
    buf.release();
    assertEquals(requestId, response.getRequestId());
    assertTrue("Did not respond with expected failure cause", response.getCause() instanceof UnknownKvStateIdException);
    assertEquals(1L, stats.getNumRequests());
    assertEquals(1L, stats.getNumFailed());
}
Also used : KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) UnknownKvStateIdException(org.apache.flink.queryablestate.exceptions.UnknownKvStateIdException) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) KvStateServerHandler(org.apache.flink.queryablestate.server.KvStateServerHandler) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) KvStateID(org.apache.flink.queryablestate.KvStateID) RequestFailure(org.apache.flink.queryablestate.network.messages.RequestFailure) AtomicKvStateRequestStats(org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats) Test(org.junit.Test)

Example 12 with KvStateID

use of org.apache.flink.queryablestate.KvStateID in project flink by apache.

the class KvStateServerHandlerTest method testIncomingBufferIsRecycled.

/**
 * Tests that incoming buffer instances are recycled.
 */
@Test
public void testIncomingBufferIsRecycled() throws Exception {
    KvStateRegistry registry = new KvStateRegistry();
    AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();
    MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
    KvStateServerHandler handler = new KvStateServerHandler(testServer, registry, serializer, stats);
    EmbeddedChannel channel = new EmbeddedChannel(getFrameDecoder(), handler);
    KvStateInternalRequest request = new KvStateInternalRequest(new KvStateID(), new byte[0]);
    ByteBuf serRequest = MessageSerializer.serializeRequest(channel.alloc(), 282872L, request);
    assertEquals(1L, serRequest.refCnt());
    // Write regular request
    channel.writeInbound(serRequest);
    assertEquals("Buffer not recycled", 0L, serRequest.refCnt());
    // Write unexpected msg
    ByteBuf unexpected = channel.alloc().buffer(8);
    unexpected.writeInt(4);
    unexpected.writeInt(4);
    assertEquals(1L, unexpected.refCnt());
    channel.writeInbound(unexpected);
    assertEquals("Buffer not recycled", 0L, unexpected.refCnt());
    channel.finishAndReleaseAll();
}
Also used : KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) KvStateServerHandler(org.apache.flink.queryablestate.server.KvStateServerHandler) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) KvStateID(org.apache.flink.queryablestate.KvStateID) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) AtomicKvStateRequestStats(org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats) Test(org.junit.Test)

Example 13 with KvStateID

use of org.apache.flink.queryablestate.KvStateID in project flink by apache.

the class MessageSerializerTest method testRequestSerialization.

/**
 * Tests request serialization.
 */
@Test
public void testRequestSerialization() throws Exception {
    long requestId = Integer.MAX_VALUE + 1337L;
    KvStateID kvStateId = new KvStateID();
    byte[] serializedKeyAndNamespace = randomByteArray(1024);
    final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
    final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
    ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
    int frameLength = buf.readInt();
    assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
    assertEquals(requestId, MessageSerializer.getRequestId(buf));
    KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
    assertEquals(buf.readerIndex(), frameLength + 4);
    assertEquals(kvStateId, requestDeser.getKvStateId());
    assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}
Also used : MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) KvStateID(org.apache.flink.queryablestate.KvStateID) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 14 with KvStateID

use of org.apache.flink.queryablestate.KvStateID in project flink by apache.

the class MessageSerializerTest method testRequestSerializationWithZeroLengthKeyAndNamespace.

/**
 * Tests request serialization with zero-length serialized key and namespace.
 */
@Test
public void testRequestSerializationWithZeroLengthKeyAndNamespace() throws Exception {
    long requestId = Integer.MAX_VALUE + 1337L;
    KvStateID kvStateId = new KvStateID();
    byte[] serializedKeyAndNamespace = new byte[0];
    final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
    final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer = new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
    ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
    int frameLength = buf.readInt();
    assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
    assertEquals(requestId, MessageSerializer.getRequestId(buf));
    KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
    assertEquals(buf.readerIndex(), frameLength + 4);
    assertEquals(kvStateId, requestDeser.getKvStateId());
    assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}
Also used : MessageSerializer(org.apache.flink.queryablestate.network.messages.MessageSerializer) KvStateInternalRequest(org.apache.flink.queryablestate.messages.KvStateInternalRequest) KvStateID(org.apache.flink.queryablestate.KvStateID) KvStateResponse(org.apache.flink.queryablestate.messages.KvStateResponse) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 15 with KvStateID

use of org.apache.flink.queryablestate.KvStateID in project flink by apache.

the class JobMasterQueryableStateTest method testUnregisterKvState.

@Test
public void testUnregisterKvState() throws Exception {
    final JobMaster jobMaster = new JobMasterBuilder(JOB_GRAPH, rpcService).createJobMaster();
    jobMaster.start();
    final JobMasterGateway jobMasterGateway = jobMaster.getSelfGateway(JobMasterGateway.class);
    registerSlotsRequiredForJobExecution(jobMasterGateway, JOB_GRAPH.getJobID());
    try {
        final String registrationName = "register-me";
        final KvStateID kvStateID = new KvStateID();
        final KeyGroupRange keyGroupRange = new KeyGroupRange(0, 0);
        final InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1029);
        jobMasterGateway.notifyKvStateRegistered(JOB_GRAPH.getJobID(), JOB_VERTEX_1.getID(), keyGroupRange, registrationName, kvStateID, address).get();
        jobMasterGateway.notifyKvStateUnregistered(JOB_GRAPH.getJobID(), JOB_VERTEX_1.getID(), keyGroupRange, registrationName).get();
        try {
            jobMasterGateway.requestKvStateLocation(JOB_GRAPH.getJobID(), registrationName).get();
            fail("Expected to fail with an UnknownKvStateLocation.");
        } catch (Exception e) {
            assertThat(e, containsCause(UnknownKvStateLocation.class));
        }
    } finally {
        RpcUtils.terminateRpcEndpoint(jobMaster, testingTimeout);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) KvStateID(org.apache.flink.queryablestate.KvStateID) JobMasterBuilder(org.apache.flink.runtime.jobmaster.utils.JobMasterBuilder) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Test(org.junit.Test)

Aggregations

KvStateID (org.apache.flink.queryablestate.KvStateID)21 Test (org.junit.Test)20 InetSocketAddress (java.net.InetSocketAddress)11 KvStateInternalRequest (org.apache.flink.queryablestate.messages.KvStateInternalRequest)11 KvStateResponse (org.apache.flink.queryablestate.messages.KvStateResponse)11 MessageSerializer (org.apache.flink.queryablestate.network.messages.MessageSerializer)11 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)11 JobID (org.apache.flink.api.common.JobID)9 AtomicKvStateRequestStats (org.apache.flink.queryablestate.network.stats.AtomicKvStateRequestStats)9 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)9 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)8 UnknownHostException (java.net.UnknownHostException)7 ExecutionException (java.util.concurrent.ExecutionException)7 ConnectException (java.net.ConnectException)6 ClosedChannelException (java.nio.channels.ClosedChannelException)6 ArrayList (java.util.ArrayList)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)4 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)4