summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java')
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java
new file mode 100644
index 00000000000..12d258b2478
--- /dev/null
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/ConcurrentDocumentOperationBlockerTest.java
@@ -0,0 +1,63 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.http.client.core.operationProcessor;
+
+import com.yahoo.vespa.http.client.core.operationProcessor.ConcurrentDocumentOperationBlocker;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+public class ConcurrentDocumentOperationBlockerTest {
+
+ final ConcurrentDocumentOperationBlocker blocker = new ConcurrentDocumentOperationBlocker();
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ @Before
+ public void setup() throws InterruptedException {
+ blocker.setMaxConcurrency(2);
+ blocker.startOperation();
+ assertThat(blocker.availablePermits(), is(1));
+ blocker.startOperation();
+ }
+
+ private void spawnThreadPushOperationThenCountDown() {
+ new Thread(() -> {
+ try {
+ blocker.startOperation();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ latch.countDown();
+ }).start();
+ }
+
+ @Test
+ public void testBasics() throws InterruptedException {
+ spawnThreadPushOperationThenCountDown();
+ assertFalse(latch.await(10, TimeUnit.MILLISECONDS));
+ blocker.operationDone();
+ assertTrue(latch.await(120, TimeUnit.SECONDS));
+ }
+
+ @Test
+ public void testResizeLarger() throws InterruptedException {
+ spawnThreadPushOperationThenCountDown();
+ assertFalse(latch.await(10, TimeUnit.MILLISECONDS));
+ blocker.setMaxConcurrency(3);
+ assertTrue(latch.await(120, TimeUnit.SECONDS));
+ }
+
+ @Test
+ public void testResizeSmaller() throws InterruptedException {
+ spawnThreadPushOperationThenCountDown();
+ blocker.setMaxConcurrency(1);
+ blocker.operationDone();
+ assertFalse(latch.await(10, TimeUnit.MILLISECONDS));
+ blocker.operationDone();
+ assertTrue(latch.await(120, TimeUnit.SECONDS));
+ }
+} \ No newline at end of file