From dfc9cdee69426b48d683e119dda9fae9154e6fde Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 1 Mar 2021 20:58:10 +0000 Subject: Improve test coverage - remove unused code - use lombok Change-Id: I8c52584249347c7ca2102022457225401f95b9a5 Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3490 --- .../java/org/openecomp/sdc/be/workers/Job.java | 29 ------- .../java/org/openecomp/sdc/be/workers/Main.java | 50 ------------ .../java/org/openecomp/sdc/be/workers/Manager.java | 91 ---------------------- .../java/org/openecomp/sdc/be/workers/Worker.java | 70 ----------------- 4 files changed, 240 deletions(-) delete mode 100644 common-be/src/main/java/org/openecomp/sdc/be/workers/Job.java delete mode 100644 common-be/src/main/java/org/openecomp/sdc/be/workers/Main.java delete mode 100644 common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java delete mode 100644 common-be/src/main/java/org/openecomp/sdc/be/workers/Worker.java (limited to 'common-be') diff --git a/common-be/src/main/java/org/openecomp/sdc/be/workers/Job.java b/common-be/src/main/java/org/openecomp/sdc/be/workers/Job.java deleted file mode 100644 index 3ed2e5e83a..0000000000 --- a/common-be/src/main/java/org/openecomp/sdc/be/workers/Job.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T 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.openecomp.sdc.be.workers; - -/** - * Created by michael on 6/24/2016. - */ -public abstract class Job { - public abstract E doWork(); - -} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/workers/Main.java b/common-be/src/main/java/org/openecomp/sdc/be/workers/Main.java deleted file mode 100644 index 572cfe22e4..0000000000 --- a/common-be/src/main/java/org/openecomp/sdc/be/workers/Main.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T 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.openecomp.sdc.be.workers; - -/** - * Created by michael on 6/24/2016. - */ -public class Main { - - public static void main(String[] args) { - - Manager manger = new Manager(); - manger.init(2); - manger.addJob(new Job() { - @Override - public String doWork() { - return "go"; - } - }); - manger.addJob(new Job() { - @Override - public String doWork() { - return "go go"; - } - }); - // try { - System.out.println(manger.start()); - // } catch (InterruptedException e) { - // e.printStackTrace(); - // } - } -} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java b/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java deleted file mode 100644 index bb426979ee..0000000000 --- a/common-be/src/main/java/org/openecomp/sdc/be/workers/Manager.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T 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.openecomp.sdc.be.workers; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import org.openecomp.sdc.common.log.wrappers.Logger; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -/** - * Created by michael on 6/24/2016. - */ -public class Manager { - private static final int TERMINATION_TIMEAUT = 30; - private static Logger log = Logger.getLogger(Manager.class.getName()); - private ExecutorService executor; - private LinkedBlockingQueue inputQueue; - private LinkedBlockingQueue outputQueue; - private int numberOfWorkers; - - public void init(int numberOfWorkers) { - log.debug("initializing workers, creating {} workers", numberOfWorkers); - this.numberOfWorkers = numberOfWorkers; - final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Worker-%d").build(); - this.executor = Executors.newFixedThreadPool(numberOfWorkers, threadFactory); - this.inputQueue = new LinkedBlockingQueue<>(); - this.outputQueue = new LinkedBlockingQueue<>(); - } - - public void addJob(T job) { - log.trace("job add to input queue"); - this.inputQueue.add(job); - } - - public LinkedBlockingQueue start() { - for (int i = 0; i < numberOfWorkers; i++) { - String workerName = "worker-" + i; - log.debug("starting worker:{}", workerName); - this.executor.submit(new Worker(workerName, this.inputQueue, this.outputQueue)); - } - executor.shutdown(); - try { - if (!executor.awaitTermination(TERMINATION_TIMEAUT, TimeUnit.MINUTES)) { - log.error("timer elapsed while waiting for the worker's to finish. "); - } - log.debug("all workers finished"); - } catch (InterruptedException e) { - log.error("failed while waiting for", e); - Thread.currentThread().interrupt(); - } - return outputQueue; - } - - // - // public static void main(String[] args) { - // ExecutorService executor = Executors.newFixedThreadPool(NTHREDS); - // for (int i = 0; i < 500; i++) { - // Runnable worker = new MyRunnable(10000000L + i); - // executor.execute(worker); - // } - // // This will make the executor accept no new threads - // // and finish all existing threads in the queue - // executor.shutdown(); - // // Wait until all threads are finish - // executor.awaitTermination(); - // System.out.println("Finished all threads"); - // } - // } -} diff --git a/common-be/src/main/java/org/openecomp/sdc/be/workers/Worker.java b/common-be/src/main/java/org/openecomp/sdc/be/workers/Worker.java deleted file mode 100644 index b5495760f2..0000000000 --- a/common-be/src/main/java/org/openecomp/sdc/be/workers/Worker.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T 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.openecomp.sdc.be.workers; - -import org.openecomp.sdc.be.config.BeEcompErrorManager; -import org.openecomp.sdc.common.log.wrappers.Logger; - -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * Created by michael on 6/24/2016. - */ -public class Worker, E> implements Runnable { - - private static final int QUEUE_POLL_TIMEAUT = 500; - private String workerName; - private LinkedBlockingQueue inputQueue; - - private LinkedBlockingQueue outputQueue; - - private static Logger log = Logger.getLogger(Worker.class.getName()); - - public Worker(String workerName, LinkedBlockingQueue inputQueue, LinkedBlockingQueue outputQueue) { - this.workerName = workerName; - this.inputQueue = inputQueue; - this.outputQueue = outputQueue; - } - - @Override - public void run() { - - try { - while (true) { - log.trace("worker:{} doing work", workerName); - T job = inputQueue.poll(QUEUE_POLL_TIMEAUT, TimeUnit.MILLISECONDS); - if (job == null) { - - log.debug("worker:{} nothing to do"); - break; - } - this.outputQueue.put(job.doWork()); - log.trace("worker:{} done with work", workerName); - } - } catch (Exception e) { - BeEcompErrorManager.getInstance().logInternalFlowError("executingJobFailed", - "failed during job execution worker" + workerName, BeEcompErrorManager.ErrorSeverity.ERROR); - log.debug("worker: {} nothing to do stoping", workerName, e); - } - } - -} -- cgit 1.2.3-korg