org.apache.flink.queryablestate.FutureUtils Java Examples
The following examples show how to use
org.apache.flink.queryablestate.FutureUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnClose() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); casSinkFunc.open(new Configuration()); Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.close(); Assert.fail("Close should have thrown an exception."); } catch (IOException e) { ExceptionUtils.findThrowable(e, candidate -> candidate == cause) .orElseThrow(() -> e); } }
Example #2
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnClose() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); casSinkFunc.open(new Configuration()); Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.close(); Assert.fail("Close should have thrown an exception."); } catch (IOException e) { ExceptionUtils.findThrowable(e, candidate -> candidate == cause) .orElseThrow(() -> e); } }
Example #3
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnInvoke() throws Exception { try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink()) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.invoke("world"); Assert.fail("Sending of second value should have failed."); } catch (IOException e) { Assert.assertEquals(cause, e.getCause()); Assert.assertEquals(0, casSinkFunc.getAcquiredPermits()); } } }
Example #4
Source File: Client.java From flink with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example #5
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnSnapshot() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); try (OneInputStreamOperatorTestHarness<String, Object> testHarness = createOpenedTestHarness(casSinkFunc)) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { testHarness.snapshot(123L, 123L); Assert.fail(); } catch (Exception e) { Optional<IOException> exCause = findSerializedThrowable(e, IOException.class, ClassLoader.getSystemClassLoader()); Assert.assertTrue(exCause.isPresent()); } } }
Example #6
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnSnapshot() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); try (OneInputStreamOperatorTestHarness<String, Object> testHarness = createOpenedTestHarness(casSinkFunc)) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { testHarness.snapshot(123L, 123L); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e.getCause() instanceof IOException); } } }
Example #7
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnInvoke() throws Exception { try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink()) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.invoke("world"); Assert.fail("Sending of second value should have failed."); } catch (IOException e) { Assert.assertEquals(cause, e.getCause()); Assert.assertEquals(0, casSinkFunc.getAcquiredPermits()); } } }
Example #8
Source File: Client.java From flink with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example #9
Source File: Client.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example #10
Source File: CassandraSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnSnapshot() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); try (OneInputStreamOperatorTestHarness<String, Object> testHarness = createOpenedTestHarness(casSinkFunc)) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { testHarness.snapshot(123L, 123L); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e.getCause() instanceof IOException); } } }
Example #11
Source File: CassandraSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnClose() throws Exception { TestCassandraSink casSinkFunc = new TestCassandraSink(); casSinkFunc.open(new Configuration()); Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.close(); Assert.fail("Close should have thrown an exception."); } catch (IOException e) { ExceptionUtils.findThrowable(e, candidate -> candidate == cause) .orElseThrow(() -> e); } }
Example #12
Source File: CassandraSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testThrowErrorOnInvoke() throws Exception { try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink()) { Exception cause = new RuntimeException(); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); try { casSinkFunc.invoke("world"); Assert.fail("Sending of second value should have failed."); } catch (IOException e) { Assert.assertEquals(cause, e.getCause()); Assert.assertEquals(0, casSinkFunc.getAcquiredPermits()); } } }
Example #13
Source File: Client.java From flink with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example #14
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } }
Example #15
Source File: LocalStandaloneFlinkResource.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Void> closeAsync() { try { distribution.stopFlinkCluster(); return CompletableFuture.completedFuture(null); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } }
Example #16
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example #17
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testIgnoreError() throws Exception { Exception cause = new RuntimeException(); CassandraFailureHandler failureHandler = failure -> Assert.assertEquals(cause, failure); try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink(failureHandler)) { casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); casSinkFunc.invoke("world"); } }
Example #18
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } }
Example #19
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example #20
Source File: Client.java From flink with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example #21
Source File: CassandraSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testIgnoreError() throws Exception { Exception cause = new RuntimeException(); CassandraFailureHandler failureHandler = failure -> Assert.assertEquals(cause, failure); try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink(failureHandler)) { casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); casSinkFunc.invoke("world"); } }
Example #22
Source File: QueryableStateClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } }
Example #23
Source File: QueryableStateClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example #24
Source File: Client.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example #25
Source File: CassandraSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test(timeout = DEFAULT_TEST_TIMEOUT) public void testIgnoreError() throws Exception { Exception cause = new RuntimeException(); CassandraFailureHandler failureHandler = failure -> Assert.assertEquals(cause, failure); try (TestCassandraSink casSinkFunc = createOpenedTestCassandraSink(failureHandler)) { casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.enqueueCompletableFuture(FutureUtils.getFailedFuture(cause)); casSinkFunc.invoke("hello"); casSinkFunc.invoke("world"); } }