diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-12-01 14:13:13 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-12-01 14:13:13 +0100 |
commit | 9c3c3967f9574c08da66b5d2bea26e6c298f0546 (patch) | |
tree | 32fcd726dad3c760c658852f6790857ad1c57027 /clustercontroller-apps/src/test/java | |
parent | 008477111ac92e2eec81596a5037a205bbea53ff (diff) |
Move code in clustercontroller-apputils into clustercontroller-apps
Code in clustercontroller-apputils is now only used from clustercontroller-apps,
so those two modules can be merged
Diffstat (limited to 'clustercontroller-apps/src/test/java')
2 files changed, 93 insertions, 0 deletions
diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscHttpRequestHandlerTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscHttpRequestHandlerTest.java new file mode 100644 index 00000000000..2326189a369 --- /dev/null +++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscHttpRequestHandlerTest.java @@ -0,0 +1,47 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.clustercontroller.apputil.communication.http; + +import com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * The handler is mostly tested through the apache tests, using it as endpoint here.. + * This test class is just to test some special cases. + */ +public class JDiscHttpRequestHandlerTest { + + private ThreadPoolExecutor executor; + + @Before + public void setUp() { + executor = new ThreadPoolExecutor(10, 100, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000)); + } + + public void tearDown() { + executor.shutdown(); + } + + @Test + public void testInvalidMethod() throws Exception { + try{ + HttpRequest request = new HttpRequest(); + JDiscHttpRequestHandler.setOperation(request, com.yahoo.jdisc.http.HttpRequest.Method.CONNECT); + fail("Control should not reach here"); + } catch (IllegalStateException e) { + assertEquals("Unhandled method CONNECT", e.getMessage()); + } + } + + @Test + public void testNothingButAddCoverage() throws Exception { + new JDiscHttpRequestHandler.EmptyCompletionHandler().failed(null); + } +} diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscMetricWrapperTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscMetricWrapperTest.java new file mode 100644 index 00000000000..13abfa0ecd5 --- /dev/null +++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscMetricWrapperTest.java @@ -0,0 +1,46 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.clustercontroller.apputil.communication.http; + +import com.yahoo.jdisc.Metric; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class JDiscMetricWrapperTest { + + class MetricImpl implements Metric { + int calls = 0; + @Override + public void set(String s, Number number, Context context) { ++calls; } + @Override + public void add(String s, Number number, Context context) { ++calls; } + @Override + public Context createContext(Map<String, ?> stringMap) { + ++calls; + return new Context() {}; + } + }; + + @Test + public void testSimple() { + MetricImpl impl1 = new MetricImpl(); + MetricImpl impl2 = new MetricImpl(); + JDiscMetricWrapper wrapper = new JDiscMetricWrapper(impl1); + wrapper.add("foo", 234, null); + wrapper.set("bar", 234, null); + assertTrue(wrapper.createContext(null) != null); + assertEquals(3, impl1.calls); + impl1.calls = 0; + wrapper.updateMetricImplementation(impl2); + wrapper.add("foo", 234, wrapper.createContext(null)); + wrapper.set("bar", 234, wrapper.createContext(null)); + assertTrue(wrapper.createContext(null) != null); + assertEquals(0, impl1.calls); + assertEquals(5, impl2.calls); + + } + +} |