flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] azagrebin commented on a change in pull request #6782: [FLINK-9083][Cassandra Connector] Add async backpressure support to Cassandra Connector
Date Thu, 11 Oct 2018 15:12:22 GMT
azagrebin commented on a change in pull request #6782: [FLINK-9083][Cassandra Connector] Add
async backpressure support to Cassandra Connector
URL: https://github.com/apache/flink/pull/6782#discussion_r224486164
 
 

 ##########
 File path: flink-connectors/flink-connector-cassandra/src/test/java/org/apache/flink/streaming/connectors/cassandra/CassandraSinkBaseTest.java
 ##########
 @@ -204,23 +206,113 @@ public void go() throws Exception {
 			Thread.sleep(5);
 		}
 
-		Assert.assertEquals(1, casSinkFunc.getNumOfPendingRecords());
+		Assert.assertEquals(1, casSinkFunc.getAcquiredPermits());
 		completableFuture.complete(null);
-		Assert.assertEquals(0, casSinkFunc.getNumOfPendingRecords());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
 	}
 
-	private static class TestCassandraSink extends CassandraSinkBase<String, ResultSet>
{
+	@Test(timeout = 5000)
+	public void testAcquireOnInvoke() throws Exception {
+		TestCassandraSink casSinkFunc = new TestCassandraSink();
+		casSinkFunc.setMaxConcurrentRequests(1, 5, TimeUnit.MILLISECONDS);
+
+		casSinkFunc.open(new Configuration());
+
+		CompletableFuture<ResultSet> completableFuture = new CompletableFuture<>();
+
+		casSinkFunc.setResultSetFuture(ResultSetFutures.fromCompletableFuture(completableFuture));
+
+		Assert.assertEquals(1, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
+
+		casSinkFunc.invoke("hello");
+
+		Assert.assertEquals(0, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(1, casSinkFunc.getAcquiredPermits());
+
+		completableFuture.complete(null);
+
+		casSinkFunc.close();
+	}
+
+	@Test(timeout = 5000)
+	public void testReleaseOnSuccess() throws Exception {
+		TestCassandraSink casSinkFunc = new TestCassandraSink();
+		casSinkFunc.setMaxConcurrentRequests(1, 5, TimeUnit.MILLISECONDS);
+
+		casSinkFunc.open(new Configuration());
+
+		CompletableFuture<ResultSet> completableFuture = new CompletableFuture<>();
+
+		casSinkFunc.setResultSetFuture(ResultSetFutures.fromCompletableFuture(completableFuture));
+
+		Assert.assertEquals(1, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
+
+		casSinkFunc.invoke("hello");
+
+		Assert.assertEquals(0, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(1, casSinkFunc.getAcquiredPermits());
+
+		completableFuture.complete(null);
+
+		Assert.assertEquals(1, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
+
+		casSinkFunc.close();
+	}
+
+	@Test(timeout = 5000)
+	public void testReleaseOnFailure() throws Exception {
+		TestCassandraSink casSinkFunc = new TestCassandraSink();
+		casSinkFunc.setMaxConcurrentRequests(1, 5, TimeUnit.MILLISECONDS);
+
+		casSinkFunc.open(new Configuration());
+
+		CompletableFuture<ResultSet> completableFuture = new CompletableFuture<>();
+
+		casSinkFunc.setResultSetFuture(ResultSetFutures.fromCompletableFuture(completableFuture));
+
+		Assert.assertEquals(1, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
+
+		casSinkFunc.invoke("hello");
+
+		Assert.assertEquals(0, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(1, casSinkFunc.getAcquiredPermits());
+
+		completableFuture.completeExceptionally(new RuntimeException());
+
+		Assert.assertEquals(1, casSinkFunc.getAvailablePermits());
+		Assert.assertEquals(0, casSinkFunc.getAcquiredPermits());
+	}
+
+	@Test(timeout = 5000)
+	public void testTimeoutExceptionOnInvoke() throws Exception {
+		TestCassandraSink casSinkFunc = new TestCassandraSink();
+		casSinkFunc.setMaxConcurrentRequests(0, 5, TimeUnit.MILLISECONDS);
+
+		casSinkFunc.open(new Configuration());
+
+		casSinkFunc.setResultSetFuture(ResultSetFutures.fromCompletableFuture(CompletableFuture.completedFuture(null)));
 
+		try {
+			casSinkFunc.invoke("hello");
+			Assert.fail("Sending value should have experienced a TimeoutException");
+		} catch (Exception e) {
+			Assert.assertTrue(e instanceof TimeoutException);
+		}
+	}
 
 Review comment:
   also casSinkFunc.close();?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message