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 org.junit.Rule;
24 import org.junit.rules.TestName;
25 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
26 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
27 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
29 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
30 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
31 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
32 import org.testng.annotations.Test;
34 import java.util.concurrent.CountDownLatch;
35 import java.util.concurrent.ExecutorService;
36 import java.util.concurrent.Executors;
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 static class WorkerThread implements Runnable {
52 CountDownLatch countDownLatch;
55 public WorkerThread(int threadIndex, CountDownLatch countDownLatch) {
56 this.threadIndex = threadIndex;
57 this.countDownLatch = countDownLatch;
62 System.out.println("**** Thread started " + threadIndex);
64 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails,
65 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
66 String id = ResponseParser.getUniqueIdFromResponse(createResource);
67 // System.out.println("**** Thread " + threadIndex + " create
68 // resource status " + createResource.getErrorCode() + " id = "
69 // + id + " error " + createResource.getResponse());
70 // assertEquals("**** create resource: " +
71 // createResource.getErrorCode() + " thread " + threadIndex,
73 } catch (Exception e) {
74 // System.out.println("**** Thread " + threadIndex + " exception
77 countDownLatch.countDown();
78 // System.out.println("**** Thread finished " + threadIndex);
82 // public void run_() {
83 // System.out.println("**** Thread started " + threadIndex);
85 // UserUtils userUtils = new UserUtils();
86 // User userDetails = new User(userFirstName, userLastName,
87 // httpCspUserId, email, role , 0L);
88 // RestResponse response =
89 // userUtils.createUserTowardsCatalogBe(userDetails,
90 // userUtils.getUserDetailesAdmin());
91 // System.out.println("**** Thread " + threadIndex + " create resource
92 // status " + response.getErrorCode() + " response " +
93 // response.getResponse());
94 //// assertEquals("**** create resource: " +
95 // createResource.getErrorCode() + " thread " + threadIndex, 201,
97 // } catch (Exception e) {
98 // System.out.println("**** Thread " + threadIndex + " exception " + e);
100 // countDownLatch.countDown();
101 // System.out.println("**** Thread finished " + threadIndex);
107 public void create2Resources() throws InterruptedException {
109 CountDownLatch countDownLatch = new CountDownLatch(threadCount);
110 ExecutorService executor = Executors.newFixedThreadPool(threadCount);
111 for (int i = 0; i < threadCount; i++) {
112 Runnable worker = new WorkerThread(i + 1, countDownLatch);
113 executor.execute(worker);
115 countDownLatch.await();
116 // System.out.println(" finished ");