diff options
author | Michael Dürre <michael.duerre@highstreet-technologies.com> | 2022-07-20 09:32:50 +0200 |
---|---|---|
committer | Michael Dürre <michael.duerre@highstreet-technologies.com> | 2022-07-21 12:38:52 +0200 |
commit | 25423c50e504676f15c7a57c03aad40bfc35c7e6 (patch) | |
tree | 811649e2ec44e0332e601c6563e00e914d355b9a /sdnr/wt/common/src/test | |
parent | cea47224b7b6afdd7b3d3ead8d08baf46eadc575 (diff) |
migrate sdnr features to sulfur
fix sdnr code for sulfur
Issue-ID: CCSDK-3692
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Change-Id: I0a62ade424bb978222e7ce6450215fb327f957b7
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common/src/test')
3 files changed, 103 insertions, 8 deletions
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestBaseHttpClient.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestBaseHttpClient.java index 3584d7f28..253b790eb 100644 --- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestBaseHttpClient.java +++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestBaseHttpClient.java @@ -25,7 +25,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; @@ -33,18 +35,12 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; - -@SuppressWarnings("restriction") public class TestBaseHttpClient { public static final String HTTPMETHOD_GET = "GET"; diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestKeybasedThreadpool.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestKeybasedThreadpool.java new file mode 100644 index 000000000..868275690 --- /dev/null +++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestKeybasedThreadpool.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.common.test; + +import java.util.Random; + +import org.junit.Ignore; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.threading.GenericRunnableFactory; +import org.onap.ccsdk.features.sdnr.wt.common.threading.KeyBasedThreadpool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestKeybasedThreadpool { + + + private static final Logger LOG = LoggerFactory.getLogger(TestKeybasedThreadpool.class); + private static final String KEY_A = "a"; + private static final String KEY_B = "b"; + private static final String KEY_C = "c"; + private static final String KEY_D = "d"; + + @Ignore + @Test + public void test1() { + GenericRunnableFactory<String, TestClass> factory1 = + new GenericRunnableFactory<String, TestKeybasedThreadpool.TestClass>() { + @Override + public Runnable create(final String key, final TestClass arg) { + return new Runnable() { + + @Override + public void run() { + final String key2 = arg.value; + final long sleep = arg.sleep; + LOG.info("{}: sleeping now for {} seconds",key2, sleep); + try { + Thread.sleep(sleep*1000); + } catch (InterruptedException e) { + LOG.error("InterruptedException",e); + Thread.currentThread().interrupt(); + } + LOG.info("{}: finished",key2); + } + }; + } + }; + LOG.info("starting"); + KeyBasedThreadpool<String, TestClass> threadpool = new KeyBasedThreadpool<String, TestClass>(10, 1, factory1); + threadpool.execute(KEY_A, new TestClass(KEY_A)); + threadpool.execute(KEY_A, new TestClass(KEY_A)); + threadpool.execute(KEY_A, new TestClass(KEY_A)); + threadpool.execute(KEY_B, new TestClass(KEY_B)); + threadpool.execute(KEY_C, new TestClass(KEY_C)); + threadpool.execute(KEY_D, new TestClass(KEY_D)); + threadpool.execute(KEY_D, new TestClass(KEY_D)); + threadpool.join(); + LOG.info("done"); + } + + private static int counter=0; + + + public class TestClass { + protected final long sleep; + private final String value; + + public TestClass(String value) { + + this.value = value+ String.valueOf(counter++); + Random rnd = new Random(); + this.sleep = rnd.nextInt(20); + LOG.info("instatiate {}",this); + } + + @Override + public String toString() { + return "TestClass [sleep=" + sleep + ", value=" + value + "]"; + } + } +} diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java index a3d2c9be9..6913ec21e 100644 --- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java +++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java @@ -45,7 +45,6 @@ import org.junit.Before; import org.onap.ccsdk.features.sdnr.wt.common.test.ServletInputStreamFromByteArrayInputStream; import org.onap.ccsdk.features.sdnr.wt.common.test.ServletOutputStreamToStringWriter; -@SuppressWarnings("restriction") public class HelpServletBase { public static final String RESPONSE_GET = "This is the response get"; |