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=cca8eb6198f2453a919ef53e43e04009265ccec2;hb=f9ee2cce797cf12402dd55c406f3e270d7d2e20d;hp=745c9b3c8543356916733d03dd13162bc025da8a;hpb=412db94945c5db5d2da918f5e23bd3abcecc4d10;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..cca8eb6198 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 @@ -8,30 +8,74 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; 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.Hashtable; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.junit.Test; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties; +import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStoreConfigProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStorePropertiesContainer; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** * Unit tests for DatastoreContextIntrospector. * * @author Thomas Pantelis */ +@SuppressWarnings("checkstyle:IllegalCatch") public class DatastoreContextIntrospectorTest { + static SchemaContext SCHEMA_CONTEXT; + static DatastoreContextIntrospectorFactory INTROSPECTOR_FACTORY; + + static { + final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create(); + try { + moduleContext.addModuleInfos(Arrays.asList( + BindingReflections.getModuleInfo(DataStorePropertiesContainer.class))); + } catch (Exception e) { + throw new RuntimeException(e); + } + SCHEMA_CONTEXT = moduleContext.tryToCreateSchemaContext().get(); + + DOMSchemaService mockSchemaService = mock(DOMSchemaService.class); + doReturn(SCHEMA_CONTEXT).when(mockSchemaService).getGlobalContext(); + INTROSPECTOR_FACTORY = new DatastoreContextIntrospectorFactory(mockSchemaService, + GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); + } + + @Test + public void testYangDefaults() { + final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance( + DatastoreContext.newBuilder().shardBatchedModificationCount(2) + .transactionDebugContextEnabled(true).build()); + DatastoreContext context = introspector.getContext(); + + assertEquals(1000, context.getShardBatchedModificationCount()); + assertFalse(context.isTransactionDebugContextEnabled()); + } + @Test public void testUpdate() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); - DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); + final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); - 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"); @@ -41,6 +85,7 @@ public class DatastoreContextIntrospectorTest { properties.put("shard-transaction-commit-queue-capacity", "567"); properties.put("shard-initialization-timeout-in-seconds", "82"); properties.put("shard-leader-election-timeout-in-seconds", "66"); + properties.put("initial-settle-timeout-multiplier", "5"); properties.put("shard-isolated-leader-check-interval-in-millis", "123"); properties.put("shard-snapshot-data-threshold-percentage", "100"); properties.put("shard-election-timeout-factor", "21"); @@ -51,13 +96,14 @@ public class DatastoreContextIntrospectorTest { properties.put(" max shard data change listener queue size", "2222"); properties.put("mAx-shaRd-data-STORE-executor-quEUe-size", "3333"); properties.put("persistent", "false"); + properties.put("initial-payload-serialized-buffer-capacity", "600"); boolean updated = introspector.update(properties); - assertEquals("updated", true, updated); - context = introspector.getContext(); + assertTrue("updated", updated); + DatastoreContext 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()); @@ -65,6 +111,7 @@ public class DatastoreContextIntrospectorTest { assertEquals(567, context.getShardTransactionCommitQueueCapacity()); assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds()); assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds()); + assertEquals(5, context.getInitialSettleTimeoutMultiplier()); assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis()); assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage()); assertEquals(21, context.getShardRaftConfig().getElectionTimeoutFactor()); @@ -74,22 +121,24 @@ public class DatastoreContextIntrospectorTest { assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize()); assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize()); assertEquals(3333, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize()); - assertEquals(false, context.isPersistent()); + assertEquals(600, context.getInitialPayloadSerializedBufferCapacity()); + assertFalse(context.isPersistent()); properties.put("shard-transaction-idle-timeout-in-minutes", "32"); properties.put("operation-timeout-in-seconds", "27"); properties.put("shard-heartbeat-interval-in-millis", "102"); properties.put("shard-election-timeout-factor", "22"); + properties.put("initial-settle-timeout-multiplier", "6"); properties.put("max-shard-data-change-executor-pool-size", "42"); properties.put("max-shard-data-store-executor-queue-size", "4444"); properties.put("persistent", "true"); updated = introspector.update(properties); - assertEquals("updated", true, updated); + assertTrue("updated", updated); 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()); @@ -97,6 +146,7 @@ public class DatastoreContextIntrospectorTest { assertEquals(567, context.getShardTransactionCommitQueueCapacity()); assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds()); assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds()); + assertEquals(6, context.getInitialSettleTimeoutMultiplier()); assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis()); assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage()); assertEquals(22, context.getShardRaftConfig().getElectionTimeoutFactor()); @@ -105,22 +155,21 @@ public class DatastoreContextIntrospectorTest { assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize()); assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize()); assertEquals(4444, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize()); - assertEquals(true, context.isPersistent()); + assertTrue(context.isPersistent()); updated = introspector.update(null); - assertEquals("updated", false, updated); + assertFalse("updated", updated); - updated = introspector.update(new Hashtable()); - assertEquals("updated", false, updated); + updated = introspector.update(new HashMap<>()); + assertFalse("updated", updated); } @Test public void testUpdateWithInvalidValues() { - DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build(); - DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context ); + final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); - 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,16 +182,17 @@ 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); - assertEquals("updated", true, updated); - context = introspector.getContext(); + final boolean updated = introspector.update(properties); + assertTrue("updated", updated); + DatastoreContext context = introspector.getContext(); assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout()); 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 +203,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,24 +215,67 @@ 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); + final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); boolean updated = operIntrospector.update(properties); - assertEquals("updated", true, updated); - operContext = operIntrospector.getContext(); + assertTrue("updated", updated); + DatastoreContext operContext = operIntrospector.getContext(); assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(true, operContext.isPersistent()); + assertTrue(operContext.isPersistent()); assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); - DatastoreContext configContext = DatastoreContext.newBuilder().dataStoreType("config").build(); - DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext); + final DatastoreContextIntrospector configIntrospector = INTROSPECTOR_FACTORY.newInstance(CONFIGURATION); updated = configIntrospector.update(properties); - assertEquals("updated", true, updated); - configContext = configIntrospector.getContext(); + assertTrue("updated", updated); + DatastoreContext configContext = configIntrospector.getContext(); assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(false, configContext.isPersistent()); + assertFalse(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 + + final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); + + DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(10, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + operIntrospector.update(properties); + DatastoreContext operContext = operIntrospector.getContext(); + assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes()); + + shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology"); + assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes()); + + final DatastoreContextIntrospector configIntrospector = INTROSPECTOR_FACTORY.newInstance(CONFIGURATION); + configIntrospector.update(properties); + DatastoreContext 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()); + } }