2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.execute.resource;
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.ExecutorService;
25 import java.util.concurrent.Executors;
27 import org.junit.Rule;
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
30 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
33 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
34 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
35 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
36 import org.testng.annotations.Test;
38 public class SimultaneousApiTest extends ComponentBaseTest {
40 protected static ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
43 public static TestName name = new TestName();
45 static String httpCspUserId = "km2000";
46 static String userFirstName = "Kot";
47 static String userLastName = "Matroskin";
48 static String email = "km2000@intl.sdc.com";
49 static String role = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN).getRole();
51 public SimultaneousApiTest() {
52 super(name, SimultaneousApiTest.class.getName());
56 public static class WorkerThread implements Runnable {
57 CountDownLatch countDownLatch;
60 public WorkerThread(int threadIndex, CountDownLatch countDownLatch) {
61 this.threadIndex = threadIndex;
62 this.countDownLatch = countDownLatch;
67 System.out.println("**** Thread started " + threadIndex);
69 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails,
70 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
71 String id = ResponseParser.getUniqueIdFromResponse(createResource);
72 // System.out.println("**** Thread " + threadIndex + " create
73 // resource status " + createResource.getErrorCode() + " id = "
74 // + id + " error " + createResource.getResponse());
75 // assertEquals("**** create resource: " +
76 // createResource.getErrorCode() + " thread " + threadIndex,
78 } catch (Exception e) {
79 // System.out.println("**** Thread " + threadIndex + " exception
82 countDownLatch.countDown();
83 // System.out.println("**** Thread finished " + threadIndex);
87 // public void run_() {
88 // System.out.println("**** Thread started " + threadIndex);
90 // UserUtils userUtils = new UserUtils();
91 // User userDetails = new User(userFirstName, userLastName,
92 // httpCspUserId, email, role , 0L);
93 // RestResponse response =
94 // userUtils.createUserTowardsCatalogBe(userDetails,
95 // userUtils.getUserDetailesAdmin());
96 // System.out.println("**** Thread " + threadIndex + " create resource
97 // status " + response.getErrorCode() + " response " +
98 // response.getResponse());
99 //// assertEquals("**** create resource: " +
100 // createResource.getErrorCode() + " thread " + threadIndex, 201,
102 // } catch (Exception e) {
103 // System.out.println("**** Thread " + threadIndex + " exception " + e);
105 // countDownLatch.countDown();
106 // System.out.println("**** Thread finished " + threadIndex);
112 public void create2Resources() throws InterruptedException {
114 CountDownLatch countDownLatch = new CountDownLatch(threadCount);
115 ExecutorService executor = Executors.newFixedThreadPool(threadCount);
116 for (int i = 0; i < threadCount; i++) {
117 Runnable worker = new WorkerThread(i + 1, countDownLatch);
118 executor.execute(worker);
120 countDownLatch.await();
121 // System.out.println(" finished ");