Unit tests for ofoverlay
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / statistics / SFlowRTConnection.java
index 9a390fec785292fa77410b6f838107fefb51cd45..7189982c856d72c31d0057ef9a8707f5c5878583 100755 (executable)
@@ -21,25 +21,23 @@ public class SFlowRTConnection {
 
     private static final Logger LOG = LoggerFactory.getLogger(SFlowRTConnection.class);
 
-    private static final int CONNECT_TIMEOUT_MILLISEC = 20000;
-    private static final int READ_TIMEOUT_MILLISEC = 30000;
     private static final String GET = "GET";
     private static final String PUT = "PUT";
     private static final String DELETE = "DELETE";
 
+    static final String EX_MSG_NOT_INITIALIZED = "SFlowRTConnection is not initialized.";
+
     private final FlowCache flowCache;
     private JsonRestClient client;
     private boolean isInitialized = false;
     private final ScheduledExecutorService executor;
     private final String collectorUri;
 
-    public SFlowRTConnection(ScheduledExecutorService executor, String collectorUri, FlowCache flowCache) {
+    public SFlowRTConnection(ScheduledExecutorService executor, String collectorUri, FlowCache flowCache, JsonRestClient client) {
         this.executor = Preconditions.checkNotNull(executor);
         this.collectorUri = Preconditions.checkNotNull(collectorUri);
         this.flowCache = Preconditions.checkNotNull(flowCache);
-
-        this.client = new JsonRestClient(collectorUri, CONNECT_TIMEOUT_MILLISEC,
-                READ_TIMEOUT_MILLISEC);
+        this.client = client;
         initialize();
     }
 
@@ -60,7 +58,7 @@ public class SFlowRTConnection {
     public JsonRestClientResponse get(String path,
             MultivaluedMap<String, String> params) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         try {
             JsonRestClientResponse responce = client.get(path, params);
@@ -75,7 +73,7 @@ public class SFlowRTConnection {
     @Nullable
     public JsonRestClientResponse put(String path, String someJson) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         return putWithoutInitCheck(path, someJson);
     }
@@ -95,7 +93,7 @@ public class SFlowRTConnection {
 
     public JsonRestClientResponse delete(String path) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         try {
             JsonRestClientResponse responce = client.delete(path);