X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContextIntrospectorTest.java;h=2d6e4ebcbcaa02736c43f339a8fcb3a0f651c7e0;hp=2eb078f7900fe40f266d57e43979747da2ec1491;hb=7a28e6fd2df73b998b26cd33af7e6a34d6d348e9;hpb=995da01ef2d635230c37afc7cf4fdd724bf68856 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 2eb078f790..2d6e4ebcbc 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,8 +8,8 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; 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_MS; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_INITIALIZATION_TIMEOUT; @@ -19,45 +19,22 @@ import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEF 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.Hashtable; import java.util.Map; import org.junit.Test; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers; +import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext; 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.binding.util.BindingReflections; -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()); - } + static final DatastoreContextIntrospectorFactory INTROSPECTOR_FACTORY = new DatastoreContextIntrospectorFactory( + new BindingCodecContext(BindingRuntimeHelpers.createRuntimeContext(DataStorePropertiesContainer.class))); @Test public void testYangDefaults() { @@ -67,7 +44,7 @@ public class DatastoreContextIntrospectorTest { DatastoreContext context = introspector.getContext(); assertEquals(1000, context.getShardBatchedModificationCount()); - assertEquals(false, context.isTransactionDebugContextEnabled()); + assertFalse(context.isTransactionDebugContextEnabled()); } @Test @@ -84,6 +61,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"); @@ -94,9 +72,10 @@ 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); + assertTrue("updated", updated); DatastoreContext context = introspector.getContext(); assertEquals(31, context.getShardTransactionIdleTimeout().toMinutes()); @@ -108,6 +87,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()); @@ -117,18 +97,20 @@ 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()); @@ -140,6 +122,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()); @@ -148,13 +131,13 @@ 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); } @@ -176,7 +159,7 @@ public class DatastoreContextIntrospectorTest { properties.put("unknownProperty", "1"); // bad - invalid property name final boolean updated = introspector.update(properties); - assertEquals("updated", true, updated); + assertTrue("updated", updated); DatastoreContext context = introspector.getContext(); assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout()); @@ -210,20 +193,20 @@ public class DatastoreContextIntrospectorTest { final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); boolean updated = operIntrospector.update(properties); - assertEquals("updated", true, updated); + assertTrue("updated", updated); DatastoreContext operContext = operIntrospector.getContext(); assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(true, operContext.isPersistent()); + assertTrue(operContext.isPersistent()); assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); final DatastoreContextIntrospector configIntrospector = INTROSPECTOR_FACTORY.newInstance(CONFIGURATION); updated = configIntrospector.update(properties); - assertEquals("updated", true, updated); + assertTrue("updated", updated); DatastoreContext configContext = configIntrospector.getContext(); assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes()); - assertEquals(false, configContext.isPersistent()); + assertFalse(configContext.isPersistent()); assertEquals(444, configContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize()); } @@ -234,6 +217,7 @@ public class DatastoreContextIntrospectorTest { 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 + properties.put("config.topology.persistent", "false"); // per-shard config override final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL); @@ -254,6 +238,7 @@ public class DatastoreContextIntrospectorTest { shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology"); assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes()); + assertFalse(shardContext.isPersistent()); // operational shard override properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66"); @@ -270,5 +255,6 @@ public class DatastoreContextIntrospectorTest { shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("default"); assertEquals(44, shardContext.getShardTransactionIdleTimeout().toMinutes()); + assertTrue(shardContext.isPersistent()); } }