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 962ef8e..7b1fc57 100644 (file)
             <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>
 
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 cb36223..5520359 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 ClientActorConfig config;
 
     // 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);
+        this.config = Preconditions.checkNotNull(config);
     }
 
     @Override
@@ -52,6 +54,11 @@ public class ClientActorContext extends AbstractClientActorContext implements Id
         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
index c0790e7..91675c1 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(),
-            persistenceId(), clientId);
+            persistenceId(), clientId, actor.getClientActorConfig());
 
         return actor.initialBehavior(context);
     }
index 3a2abbe..f2c42e1 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(),
-                PERSISTENCE_ID, CLIENT_ID);
+                PERSISTENCE_ID, CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
         replyToProbe = new TestProbe(system);
         connection = createConnection();
     }
@@ -152,4 +152,4 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
         return new AbortLocalTransactionRequest(identifier, replyTo);
     }
 
-}
\ No newline at end of file
+}
@@ -7,6 +7,8 @@
  */
 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;
@@ -24,7 +26,16 @@ public class AccessClientUtil {
 
     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(
@@ -43,4 +54,4 @@ public class AccessClientUtil {
         return new ConnectionEntry(request, callback, now);
     }
 
-}
\ No newline at end of file
+}
index 7431813..6804b1f 100644 (file)
@@ -189,6 +189,25 @@ public class ActorBehaviorTest {
             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 3ecc68b..afb7659 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(),
-                PERSISTENCE_ID, CLIENT_ID);
+                PERSISTENCE_ID, CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
     }
 
     @Test
index d9a30ff..39ff815 100644 (file)
                 <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>
index 2f9381b..a444164 100644 (file)
       <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>
index 1143bab..b91ff70 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 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;
@@ -33,6 +34,11 @@ public abstract class AbstractDataStoreClientActor extends AbstractClientActor {
         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));
index 07115b7..890e103 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 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;
@@ -33,7 +34,7 @@ import scala.concurrent.duration.FiniteDuration;
  *
  * @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);
@@ -216,6 +217,7 @@ public class DatastoreContext {
         return shardManagerPersistenceId;
     }
 
+    @Override
     public String getTempFileDirectory() {
         return raftConfig.getTempFileDirectory();
     }
@@ -224,6 +226,7 @@ public class DatastoreContext {
         raftConfig.setTempFileDirectory(tempFileDirectory);
     }
 
+    @Override
     public int getFileBackedStreamingThreshold() {
         return raftConfig.getFileBackedStreamingThreshold();
     }
@@ -307,6 +310,7 @@ public class DatastoreContext {
         return useTellBasedProtocol;
     }
 
+    @Override
     public int getMaximumMessageSliceSize() {
         return maximumMessageSliceSize;
     }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.