Adding interfaces in documentation
[aai/sparky-be.git] / src / test / java / org / onap / aai / 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.onap.aai.sparky.synchronizer;
27
28 import java.util.concurrent.atomic.AtomicInteger;
29
30 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
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     NetworkStatisticsConfig tpc = new NetworkStatisticsConfig();
55
56     tpc.setNumSamplesPerThreadForRunningAverage(100);
57
58     tpc.setBytesHistogramLabel("bytesHistoLabel");
59     tpc.setBytesHistogramMaxYAxis(1000000);
60     tpc.setBytesHistogramNumBins(20);
61     tpc.setBytesHistogramNumDecimalPoints(2);
62
63     tpc.setQueueLengthHistogramLabel("queueHistoLabel");
64     tpc.setQueueLengthHistogramMaxYAxis(1000000);
65     tpc.setQueueLengthHistogramNumBins(20);
66     tpc.setQueueLengthHistogramNumDecimalPoints(2);
67
68     // ZeroDelayProcessor zdp = new ZeroDelayProcessor(LinkProcessorType.AAI, tpc);
69     // zdp.setStatCollector(this.aaiStatCollector);
70     /*
71      * zdp.setTaskProcessorConfig(tpc);
72      * 
73      * this.resolver.registerProcessor(zdp); this.resolver.registerEventListener(this); this.counter
74      * = new AtomicInteger(0); this.syncInProgress = false; }
75      * 
76      * @Override public void handleEvent(AsyncEvent event) {
77      * 
78      * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) {
79      * 
80      * if(syncInProgress) { long duration = System.currentTimeMillis() - startTimeInMs;
81      * System.out.println(getStatReport(duration)); syncInProgress = false; }
82      * 
83      * // shutdown(); } else if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
84      * 
85      * this.syncInProgress = true;
86      * 
87      * ExternalResource resource = (ExternalResource)event.getPayload();
88      * 
89      * //aaiStatCollector.updateCounters(resource);
90      * 
91      * counter.incrementAndGet();
92      * 
93      * }
94      * 
95      * };
96      * 
97      * public void shutdown() { resolver.shutdown(); }
98      * 
99      * private int getCounterValue(AtomicInteger counter) {
100      * 
101      * if(counter == null) { return 0; }
102      * 
103      * return counter.get(); }
104      * 
105      * private void addActiveInventoryStatReport(StringBuilder sb) {
106      * 
107      * if(sb == null) { return; }
108      * 
109      * sb.append("\n\n    ").append(LinkProcessorType.AAI.name());
110      * 
111      * sb.append("\n\n        ").append("REST Operational Stats:");
112      * 
113      * /* Map<String, AtomicInteger> procOperationalCounters =
114      * aaiStatCollector.getActiveInventoryOperationalCounters();
115      * 
116      * if(procOperationalCounters != null) {
117      * 
118      * int _1XX =
119      * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_1XX)); int _2XX
120      * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_2XX)); int
121      * _3XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_3XX));
122      * int _4XX =
123      * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_4XX)); int _5XX
124      * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_5XX)); int
125      * _6XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_6XX));
126      * 
127      * sb.append("\n            ").append(String.format(
128      * "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
129      * _1XX, _2XX, _3XX, _4XX, _5XX, _6XX)); }
130      */
131
132     // sb.append("\n\n ").append("Entity Stats:");
133
134     /*
135      * sort entities, then sort nested op codes
136      */
137
138     /*
139      * TreeMap<String, HashMap<String, AtomicInteger>> activeInventoryEntitySortedTreeMap = new
140      * TreeMap<String, HashMap<String, AtomicInteger>>( new Comparator<String>() {
141      * 
142      * public int compare(String o1, String o2) { return
143      * o1.toLowerCase().compareTo(o2.toLowerCase()); } });
144      */
145
146     /*
147      * activeInventoryEntitySortedTreeMap.putAll(aaiStatCollector.getActiveInventoryEntityCounters()
148      * );
149      * 
150      * for(String counterEntityKey : activeInventoryEntitySortedTreeMap.keySet()) {
151      * 
152      * HashMap<String, AtomicInteger> entityCounters =
153      * activeInventoryEntitySortedTreeMap.get(counterEntityKey);
154      * 
155      * AtomicInteger total = entityCounters.get(ActiveInventoryStatCollector.TOTAL); AtomicInteger
156      * found = entityCounters.get(ActiveInventoryStatCollector.FOUND); AtomicInteger notFound =
157      * entityCounters.get(ActiveInventoryStatCollector.NOT_FOUND); AtomicInteger error =
158      * entityCounters.get(ActiveInventoryStatCollector.ERROR);
159      * 
160      * int totalValue = (total == null) ? 0 : total.get(); int foundValue = (found == null) ? 0 :
161      * found.get(); int notFoundValue = (found == null) ? 0 : notFound.get(); int errorValue =
162      * (error == null) ? 0 : error.get();
163      * 
164      * sb.append("\n            ").append(String.format(
165      * "%-30s TOTAL: %-12d FOUND: %-12d NOT_FOUND: %-12d ERROR: %-12d", counterEntityKey,
166      * totalValue, foundValue, notFoundValue, errorValue));
167      * 
168      * }
169      */
170
171     // sb.append("\n\n ").append("Task Processor Stats:");
172
173     // int totalRetries =
174     // getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.NUM_RETRIES));
175     // int currentQueueLength = resolver.getCurrentQueueLength(LinkProcessorType.AAI.name());
176
177     /*
178      * sb.append("\n            "
179      * ).append(resolver.getProcessorTaskAgeStats(LinkProcessorType.AAI.name(), false, "          "
180      * )); sb.append("\n            "
181      * ).append(resolver.getProcessorResponseStats(LinkProcessorType.AAI.name(), false, "          "
182      * )); sb.append("\n")
183      * .append(resolver.getQueueItemLengthHistogram(LinkProcessorType.AAI.name(), false,
184      * "            ")); sb.append("\n")
185      * .append(resolver.getResponseByteSizeHistogram(LinkProcessorType.AAI.name(), false,
186      * "            ")); sb.append("\n            "
187      * ).append("TPS=").append(resolver.getTPS(LinkProcessorType.AAI.name())).append(", NumRetries="
188      * ).append(totalRetries) .append(", CurrentQueueLength=").append(currentQueueLength);
189      */
190     /*
191      * }
192      * 
193      * private String getStatReport(long syncOpTimeInMs) {
194      * 
195      * StringBuilder sb = new StringBuilder(128);
196      * 
197      * sb.append("\n").append("Async Resolver Statistics: ( Sync Operation Duration = " +
198      * NodeUtils.getDurationBreakdown(syncOpTimeInMs) + " )");
199      * 
200      * addActiveInventoryStatReport(sb);
201      * 
202      * return sb.toString();
203      * 
204      * }
205      * 
206      * public void loadResolver(int numItems) {
207      * 
208      * if(numItems <= 0) { return; }
209      * 
210      * startTimeInMs = System.currentTimeMillis();
211      * 
212      * DummyPerformanceTask dpt = null;
213      * 
214      * for(int i = 0; i < numItems; i++) {
215      * 
216      * dpt = new DummyPerformanceTask(); dpt.setLinkProcessorType(LinkProcessorType.AAI);
217      * dpt.setResourceEntityType("DummyPerformanceEntity"); dpt.setOperationType(HttpMethod.GET);
218      * 
219      * resolver.resolve(dpt);
220      * 
221      * }
222      * 
223      * }
224      * 
225      * public static void main(String[] args) throws Exception {
226      * 
227      * System.getProperties().setProperty("AJSC_HOME", "x:\\aaiui\\");
228      * 
229      * System.out.println("Available processors = " + Runtime.getRuntime().availableProcessors());
230      * 
231      * AsyncRateControlTester arcTester = new AsyncRateControlTester();
232      * 
233      * // give us time to instrument the jvm with jvisualvm // Thread.sleep(30000);
234      * Thread.sleep(5000);
235      * 
236      * arcTester.loadResolver(1000);
237      * 
238      * 
239      * }
240      */
241   }
242 }