X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContextIntrospectorTest.java;h=5d5d2f8db23ede151123bd1be66ef722c009ea59;hb=258d8039ac144aeee2efa7943228c0fc6cdaf651;hp=745c9b3c8543356916733d03dd13162bc025da8a;hpb=3927509ec3ecfa32a51b725d2b7155d425f5b877;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java index 745c9b3c85..5d5d2f8db2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java @@ -9,15 +9,18 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS; -import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_OPERATION_TIMEOUT_IN_SECONDS; +import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_OPERATION_TIMEOUT_IN_MS; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_INITIALIZATION_TIMEOUT; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS; -import java.util.Dictionary; + +import java.util.HashMap; import java.util.Hashtable; +import java.util.Map; import org.junit.Test; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStoreConfigProperties; /** * Unit tests for DatastoreContextIntrospector. @@ -28,10 +31,11 @@ public class DatastoreContextIntrospectorTest { @Test public void testUpdate() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); - DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); + DatastoreContext context = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); + final DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context); - Dictionary properties = new Hashtable<>(); + final Map properties = new HashMap<>(); properties.put("shard-transaction-idle-timeout-in-minutes", "31"); properties.put("operation-timeout-in-seconds", "26"); properties.put("shard-transaction-commit-timeout-in-seconds", "100"); @@ -57,7 +61,7 @@ public class DatastoreContextIntrospectorTest { context = introspector.getContext(); assertEquals(31, context.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(26, context.getOperationTimeoutInSeconds()); + assertEquals(26000, context.getOperationTimeoutInMillis()); assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds()); assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize()); assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount()); @@ -89,7 +93,7 @@ public class DatastoreContextIntrospectorTest { context = introspector.getContext(); assertEquals(32, context.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(27, context.getOperationTimeoutInSeconds()); + assertEquals(27000, context.getOperationTimeoutInMillis()); assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds()); assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize()); assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount()); @@ -110,17 +114,18 @@ public class DatastoreContextIntrospectorTest { updated = introspector.update(null); assertEquals("updated", false, updated); - updated = introspector.update(new Hashtable()); + updated = introspector.update(new Hashtable<>()); assertEquals("updated", false, updated); } @Test public void testUpdateWithInvalidValues() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); - DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); + DatastoreContext context = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); + final DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context); - Dictionary properties = new Hashtable<>(); + final Map properties = new HashMap<>(); properties.put("shard-transaction-idle-timeout-in-minutes", "0"); // bad - must be > 0 properties.put("shard-journal-recovery-log-batch-size", "199"); properties.put("shard-transaction-commit-timeout-in-seconds", "bogus"); // bad - NaN @@ -133,7 +138,7 @@ public class DatastoreContextIntrospectorTest { properties.put("max-shard-data-change-executor-pool-size", "bogus"); // bad - NaN properties.put("unknownProperty", "1"); // bad - invalid property name - boolean updated = introspector.update(properties); + final boolean updated = introspector.update(properties); assertEquals("updated", true, updated); context = introspector.getContext(); @@ -141,8 +146,9 @@ public class DatastoreContextIntrospectorTest { assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize()); assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds()); assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount()); - assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_SECONDS, context.getOperationTimeoutInSeconds()); - assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getHeartBeatInterval().length()); + assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_MS, context.getOperationTimeoutInMillis()); + assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, + context.getShardRaftConfig().getHeartBeatInterval().length()); assertEquals(567, context.getShardTransactionCommitQueueCapacity()); assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE, context.getShardRaftConfig().getSnapshotDataThresholdPercentage()); @@ -153,7 +159,7 @@ public class DatastoreContextIntrospectorTest { @Test public void testUpdateWithDatastoreTypeSpecificProperties() { - Dictionary properties = new Hashtable<>(); + final Map properties = new HashMap<>(); properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override @@ -165,8 +171,9 @@ public class DatastoreContextIntrospectorTest { properties.put("persistent", "false"); // global setting properties.put("operational.Persistent", "true"); // operational override - DatastoreContext operContext = DatastoreContext.newBuilder().dataStoreType("operational").build(); - DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext); + DatastoreContext operContext = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); + final DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext); boolean updated = operIntrospector.update(properties); assertEquals("updated", true, updated); operContext = operIntrospector.getContext(); @@ -175,8 +182,9 @@ public class DatastoreContextIntrospectorTest { assertEquals(true, operContext.isPersistent()); assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); - DatastoreContext configContext = DatastoreContext.newBuilder().dataStoreType("config").build(); - DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); + DatastoreContext configContext = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.CONFIGURATION).build(); + final DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); updated = configIntrospector.update(properties); assertEquals("updated", true, updated); configContext = configIntrospector.getContext(); @@ -185,4 +193,53 @@ public class DatastoreContextIntrospectorTest { assertEquals(false, configContext.isPersistent()); assertEquals(444, configContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); } + + @Test + public void testGetDatastoreContextForShard() { + final Map properties = new HashMap<>(); + properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting + properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override + properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override + properties.put("topology.shard-transaction-idle-timeout-in-minutes", "55"); // global shard override + + DatastoreContext operContext = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build(); + final DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext); + + DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(10, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + operIntrospector.update(properties); + operContext = operIntrospector.getContext(); + assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes()); + + shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + DatastoreContext configContext = DatastoreContext.newBuilder() + .logicalStoreType(LogicalDatastoreType.CONFIGURATION).build(); + final DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); + configIntrospector.update(properties); + configContext = configIntrospector.getContext(); + assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes()); + + shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + // operational shard override + properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66"); + // config shard override + properties.put("config.topology.shard-transaction-idle-timeout-in-minutes", "77"); + + operIntrospector.update(properties); + shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(66, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + configIntrospector.update(properties); + shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(77, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("default"); + assertEquals(44, shardContext.getShardTransactionIdleTimeout().toMinutes()); + } }