Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / test / java / org / openecomp / sparky / synchronizer / AsyncRateControlTester.java
1 /* 
2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
7 * All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12
13 *      http://www.apache.org/licenses/LICENSE-2.0
14
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
21
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
24 */
25
26 package org.openecomp.sparky.synchronizer;
27
28 import java.util.concurrent.atomic.AtomicInteger;
29
30 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * The Class AsyncRateControlTester.
36  */
37 public class AsyncRateControlTester {
38
39   private static Logger logger = LoggerFactory.getLogger(AsyncRateControlTester.class);
40
41   private long startTimeInMs;
42
43   private AtomicInteger counter;
44
45   protected boolean syncInProgress;
46
47   /**
48    * Instantiates a new async rate control tester.
49    *
50    * @throws Exception the exception
51    */
52   public AsyncRateControlTester() throws Exception {
53
54     TaskProcessorConfig tpc = new TaskProcessorConfig();
55
56     tpc.setMaxConcurrentWorkers(1);
57     tpc.setTransactionRateControllerEnabled(false);
58     tpc.setNumSamplesPerThreadForRunningAverage(100);
59     tpc.setTargetTps(0.25);
60
61     tpc.setBytesHistogramLabel("bytesHistoLabel");
62     tpc.setBytesHistogramMaxYAxis(1000000);
63     tpc.setBytesHistogramNumBins(20);
64     tpc.setBytesHistogramNumDecimalPoints(2);
65
66     tpc.setQueueLengthHistogramLabel("queueHistoLabel");
67     tpc.setQueueLengthHistogramMaxYAxis(1000000);
68     tpc.setQueueLengthHistogramNumBins(20);
69     tpc.setQueueLengthHistogramNumDecimalPoints(2);
70
71     // ZeroDelayProcessor zdp = new ZeroDelayProcessor(LinkProcessorType.AAI, tpc);
72     // zdp.setStatCollector(this.aaiStatCollector);
73     /*
74      * zdp.setTaskProcessorConfig(tpc);
75      * 
76      * this.resolver.registerProcessor(zdp); this.resolver.registerEventListener(this); this.counter
77      * = new AtomicInteger(0); this.syncInProgress = false; }
78      * 
79      * @Override public void handleEvent(AsyncEvent event) {
80      * 
81      * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) {
82      * 
83      * if(syncInProgress) { long duration = System.currentTimeMillis() - startTimeInMs;
84      * System.out.println(getStatReport(duration)); syncInProgress = false; }
85      * 
86      * // shutdown(); } else if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
87      * 
88      * this.syncInProgress = true;
89      * 
90      * ExternalResource resource = (ExternalResource)event.getPayload();
91      * 
92      * //aaiStatCollector.updateCounters(resource);
93      * 
94      * counter.incrementAndGet();
95      * 
96      * }
97      * 
98      * };
99      * 
100      * public void shutdown() { resolver.shutdown(); }
101      * 
102      * private int getCounterValue(AtomicInteger counter) {
103      * 
104      * if(counter == null) { return 0; }
105      * 
106      * return counter.get(); }
107      * 
108      * private void addActiveInventoryStatReport(StringBuilder sb) {
109      * 
110      * if(sb == null) { return; }
111      * 
112      * sb.append("\n\n    ").append(LinkProcessorType.AAI.name());
113      * 
114      * sb.append("\n\n        ").append("REST Operational Stats:");
115      * 
116      * /* Map<String, AtomicInteger> procOperationalCounters =
117      * aaiStatCollector.getActiveInventoryOperationalCounters();
118      * 
119      * if(procOperationalCounters != null) {
120      * 
121      * int _1XX =
122      * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_1XX)); int _2XX
123      * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_2XX)); int
124      * _3XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_3XX));
125      * int _4XX =
126      * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_4XX)); int _5XX
127      * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_5XX)); int
128      * _6XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_6XX));
129      * 
130      * sb.append("\n            ").append(String.format(
131      * "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
132      * _1XX, _2XX, _3XX, _4XX, _5XX, _6XX)); }
133      */
134
135     // sb.append("\n\n ").append("Entity Stats:");
136
137     /*
138      * sort entities, then sort nested op codes
139      */
140
141     /*
142      * TreeMap<String, HashMap<String, AtomicInteger>> activeInventoryEntitySortedTreeMap = new
143      * TreeMap<String, HashMap<String, AtomicInteger>>( new Comparator<String>() {
144      * 
145      * public int compare(String o1, String o2) { return
146      * o1.toLowerCase().compareTo(o2.toLowerCase()); } });
147      */
148
149     /*
150      * activeInventoryEntitySortedTreeMap.putAll(aaiStatCollector.getActiveInventoryEntityCounters()
151      * );
152      * 
153      * for(String counterEntityKey : activeInventoryEntitySortedTreeMap.keySet()) {
154      * 
155      * HashMap<String, AtomicInteger> entityCounters =
156      * activeInventoryEntitySortedTreeMap.get(counterEntityKey);
157      * 
158      * AtomicInteger total = entityCounters.get(ActiveInventoryStatCollector.TOTAL); AtomicInteger
159      * found = entityCounters.get(ActiveInventoryStatCollector.FOUND); AtomicInteger notFound =
160      * entityCounters.get(ActiveInventoryStatCollector.NOT_FOUND); AtomicInteger error =
161      * entityCounters.get(ActiveInventoryStatCollector.ERROR);
162      * 
163      * int totalValue = (total == null) ? 0 : total.get(); int foundValue = (found == null) ? 0 :
164      * found.get(); int notFoundValue = (found == null) ? 0 : notFound.get(); int errorValue =
165      * (error == null) ? 0 : error.get();
166      * 
167      * sb.append("\n            ").append(String.format(
168      * "%-30s TOTAL: %-12d FOUND: %-12d NOT_FOUND: %-12d ERROR: %-12d", counterEntityKey,
169      * totalValue, foundValue, notFoundValue, errorValue));
170      * 
171      * }
172      */
173
174     // sb.append("\n\n ").append("Task Processor Stats:");
175
176     // int totalRetries =
177     // getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.NUM_RETRIES));
178     // int currentQueueLength = resolver.getCurrentQueueLength(LinkProcessorType.AAI.name());
179
180     /*
181      * sb.append("\n            "
182      * ).append(resolver.getProcessorTaskAgeStats(LinkProcessorType.AAI.name(), false, "          "
183      * )); sb.append("\n            "
184      * ).append(resolver.getProcessorResponseStats(LinkProcessorType.AAI.name(), false, "          "
185      * )); sb.append("\n")
186      * .append(resolver.getQueueItemLengthHistogram(LinkProcessorType.AAI.name(), false,
187      * "            ")); sb.append("\n")
188      * .append(resolver.getResponseByteSizeHistogram(LinkProcessorType.AAI.name(), false,
189      * "            ")); sb.append("\n            "
190      * ).append("TPS=").append(resolver.getTPS(LinkProcessorType.AAI.name())).append(", NumRetries="
191      * ).append(totalRetries) .append(", CurrentQueueLength=").append(currentQueueLength);
192      */
193     /*
194      * }
195      * 
196      * private String getStatReport(long syncOpTimeInMs) {
197      * 
198      * StringBuilder sb = new StringBuilder(128);
199      * 
200      * sb.append("\n").append("Async Resolver Statistics: ( Sync Operation Duration = " +
201      * NodeUtils.getDurationBreakdown(syncOpTimeInMs) + " )");
202      * 
203      * addActiveInventoryStatReport(sb);
204      * 
205      * return sb.toString();
206      * 
207      * }
208      * 
209      * public void loadResolver(int numItems) {
210      * 
211      * if(numItems <= 0) { return; }
212      * 
213      * startTimeInMs = System.currentTimeMillis();
214      * 
215      * DummyPerformanceTask dpt = null;
216      * 
217      * for(int i = 0; i < numItems; i++) {
218      * 
219      * dpt = new DummyPerformanceTask(); dpt.setLinkProcessorType(LinkProcessorType.AAI);
220      * dpt.setResourceEntityType("DummyPerformanceEntity"); dpt.setOperationType(HttpMethod.GET);
221      * 
222      * resolver.resolve(dpt);
223      * 
224      * }
225      * 
226      * }
227      * 
228      * public static void main(String[] args) throws Exception {
229      * 
230      * System.getProperties().setProperty("AJSC_HOME", "x:\\aaiui\\");
231      * 
232      * System.out.println("Available processors = " + Runtime.getRuntime().availableProcessors());
233      * 
234      * AsyncRateControlTester arcTester = new AsyncRateControlTester();
235      * 
236      * // give us time to instrument the jvm with jvisualvm // Thread.sleep(30000);
237      * Thread.sleep(5000);
238      * 
239      * arcTester.loadResolver(1000);
240      * 
241      * 
242      * }
243      */
244   }
245 }