Bug 7449: Introduce ClientActorConfig in cds-access-client 06/59406/5
authorTom Pantelis <tompantelis@gmail.com>
Thu, 22 Jun 2017 13:28:03 +0000 (09:28 -0400)
committerRobert Varga <nite@hq.sk>
Mon, 26 Jun 2017 14:12:34 +0000 (14:12 +0000)
Upcoming changes in cds-access-client will need access to some config
params in DatastoreContext. However DatastoreContext is in
sal-distributed-datastore and thus can't be referenced in cds-access-client.
So refactor a ClientActorConfig interface with the necessary accessors.

Change-Id: I55e7291340e711c585f4fb1236a27396503d1914
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
13 files changed:
opendaylight/md-sal/cds-access-client/pom.xml
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractClientActor.java
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorConfig.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorContext.java
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/InitialClientActorContext.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AccessClientUtil.java [moved from opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/access/client/AccessClientUtil.java with 80% similarity]
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ActorBehaviorTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ClientActorContextTest.java
opendaylight/md-sal/mdsal-artifacts/pom.xml
opendaylight/md-sal/sal-distributed-datastore/pom.xml
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java

index 962ef8ed7031c540311173ab1089c15a2d910a2f..7b1fc570c45e0b491a60d53c8082bb1221cbd1e7 100644 (file)
             <failOnError>true</failOnError>
           </configuration>
         </plugin>
             <failOnError>true</failOnError>
           </configuration>
         </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <executions>
+            <execution>
+              <goals>
+                <goal>test-jar</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
       </plugins>
     </build>
 
       </plugins>
     </build>
 
index fdba64f06492b47ffa053fb28443ee28326bc628..2fb4c943079527f489cbaeb609b5c10ee9c6b8d3 100644 (file)
@@ -68,4 +68,6 @@ public abstract class AbstractClientActor extends UntypedPersistentActor {
     }
 
     protected abstract ClientActorBehavior<?> initialBehavior(ClientActorContext context);
     }
 
     protected abstract ClientActorBehavior<?> initialBehavior(ClientActorContext context);
+
+    protected abstract ClientActorConfig getClientActorConfig();
 }
 }
diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorConfig.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorConfig.java
new file mode 100644 (file)
index 0000000..460420a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.client;
+
+/**
+ * Interface for client actor configuration parameters.
+ *
+ * @author Thomas Pantelis
+ */
+public interface ClientActorConfig {
+    /**
+     * Returns the maximum size in bytes for a message slice when fragmenting messages thru the akka remoting framework.
+     *
+     * @return the maximum size in bytes
+     */
+    int getMaximumMessageSliceSize();
+
+    /**
+     * Returns the threshold in bytes before switching from storing in memory to buffering to a file when streaming
+     * large amounts of data.
+     *
+     * @return the threshold in bytes
+     */
+    int getFileBackedStreamingThreshold();
+
+    /**
+     * Returns the directory in which to create temporary files.
+     *
+     * @return the directory name
+     */
+    String getTempFileDirectory();
+}
index cb36223c26f5c7a109a006ed7989dbdee70a21a6..5520359802b3170dd278bd8b66a8b349f712edf5 100644 (file)
@@ -36,14 +36,16 @@ public class ClientActorContext extends AbstractClientActorContext implements Id
     private final ExecutionContext executionContext;
     private final ClientIdentifier identifier;
     private final Scheduler scheduler;
     private final ExecutionContext executionContext;
     private final ClientIdentifier identifier;
     private final Scheduler scheduler;
+    private final ClientActorConfig config;
 
     // Hidden to avoid subclassing
     ClientActorContext(final ActorRef self, final Scheduler scheduler, final ExecutionContext executionContext,
 
     // Hidden to avoid subclassing
     ClientActorContext(final ActorRef self, final Scheduler scheduler, final ExecutionContext executionContext,
-            final String persistenceId, final ClientIdentifier identifier) {
+            final String persistenceId, final ClientIdentifier identifier, final ClientActorConfig config) {
         super(self, persistenceId);
         this.identifier = Preconditions.checkNotNull(identifier);
         this.scheduler = Preconditions.checkNotNull(scheduler);
         this.executionContext = Preconditions.checkNotNull(executionContext);
         super(self, persistenceId);
         this.identifier = Preconditions.checkNotNull(identifier);
         this.scheduler = Preconditions.checkNotNull(scheduler);
         this.executionContext = Preconditions.checkNotNull(executionContext);
+        this.config = Preconditions.checkNotNull(config);
     }
 
     @Override
     }
 
     @Override
@@ -52,6 +54,11 @@ public class ClientActorContext extends AbstractClientActorContext implements Id
         return identifier;
     }
 
         return identifier;
     }
 
+    @Nonnull
+    public ClientActorConfig config() {
+        return config;
+    }
+
     /**
      * Return the time ticker for this {@link ClientActorContext}. This should be used for in all time-tracking
      * done within a client actor. Subclasses of {@link ClientActorBehavior} are encouraged to use
     /**
      * Return the time ticker for this {@link ClientActorContext}. This should be used for in all time-tracking
      * done within a client actor. Subclasses of {@link ClientActorBehavior} are encouraged to use
index c0790e7b279a7d2ca5c94827271d182b910e7345..91675c1895b6dd5e1b92bcdcadfecadf70bd318a 100644 (file)
@@ -36,7 +36,7 @@ final class InitialClientActorContext extends AbstractClientActorContext {
     ClientActorBehavior<?> createBehavior(final ClientIdentifier clientId) {
         final ActorSystem system = actor.getContext().system();
         final ClientActorContext context = new ClientActorContext(self(), system.scheduler(), system.dispatcher(),
     ClientActorBehavior<?> createBehavior(final ClientIdentifier clientId) {
         final ActorSystem system = actor.getContext().system();
         final ClientActorContext context = new ClientActorContext(self(), system.scheduler(), system.dispatcher(),
-            persistenceId(), clientId);
+            persistenceId(), clientId, actor.getClientActorConfig());
 
         return actor.initialBehavior(context);
     }
 
         return actor.initialBehavior(context);
     }
index 3a2abbe31cbb23493513c55aa20112989ccc8bd4..f2c42e18d4984a4acd6e2e7dfa3f189916ccb8bb 100644 (file)
@@ -66,7 +66,7 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
         backendProbe = new TestProbe(system);
         contextProbe = new TestProbe(system);
         context = new ClientActorContext(contextProbe.ref(), system.scheduler(), system.dispatcher(),
         backendProbe = new TestProbe(system);
         contextProbe = new TestProbe(system);
         context = new ClientActorContext(contextProbe.ref(), system.scheduler(), system.dispatcher(),
-                PERSISTENCE_ID, CLIENT_ID);
+                PERSISTENCE_ID, CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
         replyToProbe = new TestProbe(system);
         connection = createConnection();
     }
         replyToProbe = new TestProbe(system);
         connection = createConnection();
     }
@@ -152,4 +152,4 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
         return new AbortLocalTransactionRequest(identifier, replyTo);
     }
 
         return new AbortLocalTransactionRequest(identifier, replyTo);
     }
 
-}
\ No newline at end of file
+}
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.cluster.access.client;
 
  */
 package org.opendaylight.controller.cluster.access.client;
 
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 
 import akka.actor.ActorRef;
 import static org.mockito.Mockito.spy;
 
 import akka.actor.ActorRef;
@@ -24,7 +26,16 @@ public class AccessClientUtil {
 
     public static ClientActorContext createClientActorContext(final ActorSystem system, final ActorRef actor,
                                                               final ClientIdentifier id, final String persistenceId) {
 
     public static ClientActorContext createClientActorContext(final ActorSystem system, final ActorRef actor,
                                                               final ClientIdentifier id, final String persistenceId) {
-        return spy(new ClientActorContext(actor, system.scheduler(), system.dispatcher(), persistenceId, id));
+
+        return spy(new ClientActorContext(actor, system.scheduler(), system.dispatcher(), persistenceId, id,
+                newMockClientActorConfig()));
+    }
+
+    public static ClientActorConfig newMockClientActorConfig() {
+        ClientActorConfig mockConfig = mock(ClientActorConfig.class);
+        doReturn(2_000_000).when(mockConfig).getMaximumMessageSliceSize();
+        doReturn(1_000_000_000).when(mockConfig).getFileBackedStreamingThreshold();
+        return mockConfig;
     }
 
     public static <T extends BackendInfo> ConnectedClientConnection<T> createConnectedConnection(
     }
 
     public static <T extends BackendInfo> ConnectedClientConnection<T> createConnectedConnection(
@@ -43,4 +54,4 @@ public class AccessClientUtil {
         return new ConnectionEntry(request, callback, now);
     }
 
         return new ConnectionEntry(request, callback, now);
     }
 
-}
\ No newline at end of file
+}
index 7431813010bcf633f4002805882254fa0cfad21d..6804b1fc2571fd5217cb7fadcd2e7ba4204ef216 100644 (file)
@@ -189,6 +189,25 @@ public class ActorBehaviorTest {
             return initialBehavior;
         }
 
             return initialBehavior;
         }
 
+        @Override
+        protected ClientActorConfig getClientActorConfig() {
+            return new ClientActorConfig() {
+                @Override
+                public String getTempFileDirectory() {
+                    return null;
+                }
+
+                @Override
+                public int getMaximumMessageSliceSize() {
+                    return 2000000;
+                }
+
+                @Override
+                public int getFileBackedStreamingThreshold() {
+                    return 1000000000;
+                }
+            };
+        }
     }
 
     }
 
-}
\ No newline at end of file
+}
index 3ecc68bdb45b3f30314573893a4a622c3fc2561b..afb76591b2be24530a62a12a9217f5b1f72af31b 100644 (file)
@@ -46,7 +46,7 @@ public class ClientActorContextTest {
         system = ActorSystem.apply();
         probe = new TestProbe(system);
         ctx = new ClientActorContext(probe.ref(), system.scheduler(), system.dispatcher(),
         system = ActorSystem.apply();
         probe = new TestProbe(system);
         ctx = new ClientActorContext(probe.ref(), system.scheduler(), system.dispatcher(),
-                PERSISTENCE_ID, CLIENT_ID);
+                PERSISTENCE_ID, CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
     }
 
     @Test
     }
 
     @Test
index d9a30fffbbc8fcea2a6214f296965351faada217..39ff81553a73705f5155b2327b664aa6126c5874 100644 (file)
                 <artifactId>cds-access-client</artifactId>
                 <version>1.2.0-SNAPSHOT</version>
             </dependency>
                 <artifactId>cds-access-client</artifactId>
                 <version>1.2.0-SNAPSHOT</version>
             </dependency>
+            <dependency>
+                <groupId>org.opendaylight.controller</groupId>
+                <artifactId>cds-access-client</artifactId>
+                <version>1.2.0-SNAPSHOT</version>
+                <type>test-jar</type>
+                <scope>test</scope>
+            </dependency>
             <dependency>
                 <groupId>org.opendaylight.controller</groupId>
                 <artifactId>sal-cluster-admin-api</artifactId>
             <dependency>
                 <groupId>org.opendaylight.controller</groupId>
                 <artifactId>sal-cluster-admin-api</artifactId>
index 2f9381b2c2271b5edf2e72e8830dd5eb2f328a4f..a4441642748bf1e8bddde60627c9e74a883e0303 100644 (file)
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>cds-access-client</artifactId>
     </dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>cds-access-client</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>cds-access-client</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>cds-dom-api</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>cds-dom-api</artifactId>
index 1143bab10c39993f1d51672e6543ed94ea5a2a9a..b91ff70b62fab26bb93ca5e1f89411be41c83148 100644 (file)
@@ -15,6 +15,7 @@ import com.google.common.base.Verify;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
+import org.opendaylight.controller.cluster.access.client.ClientActorConfig;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.common.actor.ExplicitAsk;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.common.actor.ExplicitAsk;
@@ -33,6 +34,11 @@ public abstract class AbstractDataStoreClientActor extends AbstractClientActor {
         this.actorContext = Preconditions.checkNotNull(actorContext);
     }
 
         this.actorContext = Preconditions.checkNotNull(actorContext);
     }
 
+    @Override
+    protected ClientActorConfig getClientActorConfig() {
+        return actorContext.getDatastoreContext();
+    }
+
     @Override
     protected final AbstractDataStoreClientBehavior initialBehavior(final ClientActorContext context) {
         return Verify.verifyNotNull(initialBehavior(context, actorContext));
     @Override
     protected final AbstractDataStoreClientBehavior initialBehavior(final ClientActorContext context) {
         return Verify.verifyNotNull(initialBehavior(context, actorContext));
index 07115b71699095e4891d819759dc5a3016aad6c0..890e1030674d3e7a3c68dbb8784a05aa82b7da1b 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import org.apache.commons.lang3.text.WordUtils;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import org.apache.commons.lang3.text.WordUtils;
+import org.opendaylight.controller.cluster.access.client.ClientActorConfig;
 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
 import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader;
 import org.opendaylight.controller.cluster.raft.ConfigParams;
 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
 import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader;
 import org.opendaylight.controller.cluster.raft.ConfigParams;
@@ -33,7 +34,7 @@ import scala.concurrent.duration.FiniteDuration;
  *
  * @author Thomas Pantelis
  */
  *
  * @author Thomas Pantelis
  */
-public class DatastoreContext {
+public class DatastoreContext implements ClientActorConfig {
     public static final String METRICS_DOMAIN = "org.opendaylight.controller.cluster.datastore";
 
     public static final Duration DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT = Duration.create(10, TimeUnit.MINUTES);
     public static final String METRICS_DOMAIN = "org.opendaylight.controller.cluster.datastore";
 
     public static final Duration DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT = Duration.create(10, TimeUnit.MINUTES);
@@ -216,6 +217,7 @@ public class DatastoreContext {
         return shardManagerPersistenceId;
     }
 
         return shardManagerPersistenceId;
     }
 
+    @Override
     public String getTempFileDirectory() {
         return raftConfig.getTempFileDirectory();
     }
     public String getTempFileDirectory() {
         return raftConfig.getTempFileDirectory();
     }
@@ -224,6 +226,7 @@ public class DatastoreContext {
         raftConfig.setTempFileDirectory(tempFileDirectory);
     }
 
         raftConfig.setTempFileDirectory(tempFileDirectory);
     }
 
+    @Override
     public int getFileBackedStreamingThreshold() {
         return raftConfig.getFileBackedStreamingThreshold();
     }
     public int getFileBackedStreamingThreshold() {
         return raftConfig.getFileBackedStreamingThreshold();
     }
@@ -307,6 +310,7 @@ public class DatastoreContext {
         return useTellBasedProtocol;
     }
 
         return useTellBasedProtocol;
     }
 
+    @Override
     public int getMaximumMessageSliceSize() {
         return maximumMessageSliceSize;
     }
     public int getMaximumMessageSliceSize() {
         return maximumMessageSliceSize;
     }