2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS;
12 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_OPERATION_TIMEOUT_IN_MS;
13 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
14 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE;
15 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
16 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
17 import java.util.Dictionary;
18 import java.util.Hashtable;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
24 * Unit tests for DatastoreContextIntrospector.
26 * @author Thomas Pantelis
28 public class DatastoreContextIntrospectorTest {
31 public void testUpdate() {
32 DatastoreContext context = DatastoreContext.newBuilder().
33 logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
34 DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
36 Dictionary<String, Object> properties = new Hashtable<>();
37 properties.put("shard-transaction-idle-timeout-in-minutes", "31");
38 properties.put("operation-timeout-in-seconds", "26");
39 properties.put("shard-transaction-commit-timeout-in-seconds", "100");
40 properties.put("shard-journal-recovery-log-batch-size", "199");
41 properties.put("shard-snapshot-batch-count", "212");
42 properties.put("shard-heartbeat-interval-in-millis", "101");
43 properties.put("shard-transaction-commit-queue-capacity", "567");
44 properties.put("shard-initialization-timeout-in-seconds", "82");
45 properties.put("shard-leader-election-timeout-in-seconds", "66");
46 properties.put("shard-isolated-leader-check-interval-in-millis", "123");
47 properties.put("shard-snapshot-data-threshold-percentage", "100");
48 properties.put("shard-election-timeout-factor", "21");
49 properties.put("shard-batched-modification-count", "901");
50 properties.put("transactionCreationInitialRateLimit", "200");
51 properties.put("MaxShardDataChangeExecutorPoolSize", "41");
52 properties.put("Max-Shard-Data-Change Executor-Queue Size", "1111");
53 properties.put(" max shard data change listener queue size", "2222");
54 properties.put("mAx-shaRd-data-STORE-executor-quEUe-size", "3333");
55 properties.put("persistent", "false");
57 boolean updated = introspector.update(properties);
58 assertEquals("updated", true, updated);
59 context = introspector.getContext();
61 assertEquals(31, context.getShardTransactionIdleTimeout().toMinutes());
62 assertEquals(26000, context.getOperationTimeoutInMillis());
63 assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
64 assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
65 assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
66 assertEquals(101, context.getShardRaftConfig().getHeartBeatInterval().length());
67 assertEquals(567, context.getShardTransactionCommitQueueCapacity());
68 assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
69 assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
70 assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
71 assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
72 assertEquals(21, context.getShardRaftConfig().getElectionTimeoutFactor());
73 assertEquals(901, context.getShardBatchedModificationCount());
74 assertEquals(200, context.getTransactionCreationInitialRateLimit());
75 assertEquals(41, context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
76 assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize());
77 assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize());
78 assertEquals(3333, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize());
79 assertEquals(false, context.isPersistent());
81 properties.put("shard-transaction-idle-timeout-in-minutes", "32");
82 properties.put("operation-timeout-in-seconds", "27");
83 properties.put("shard-heartbeat-interval-in-millis", "102");
84 properties.put("shard-election-timeout-factor", "22");
85 properties.put("max-shard-data-change-executor-pool-size", "42");
86 properties.put("max-shard-data-store-executor-queue-size", "4444");
87 properties.put("persistent", "true");
89 updated = introspector.update(properties);
90 assertEquals("updated", true, updated);
91 context = introspector.getContext();
93 assertEquals(32, context.getShardTransactionIdleTimeout().toMinutes());
94 assertEquals(27000, context.getOperationTimeoutInMillis());
95 assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
96 assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
97 assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
98 assertEquals(102, context.getShardRaftConfig().getHeartBeatInterval().length());
99 assertEquals(567, context.getShardTransactionCommitQueueCapacity());
100 assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
101 assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
102 assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
103 assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
104 assertEquals(22, context.getShardRaftConfig().getElectionTimeoutFactor());
105 assertEquals(200, context.getTransactionCreationInitialRateLimit());
106 assertEquals(42, context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
107 assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize());
108 assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize());
109 assertEquals(4444, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize());
110 assertEquals(true, context.isPersistent());
112 updated = introspector.update(null);
113 assertEquals("updated", false, updated);
115 updated = introspector.update(new Hashtable<String, Object>());
116 assertEquals("updated", false, updated);
121 public void testUpdateWithInvalidValues() {
122 DatastoreContext context = DatastoreContext.newBuilder().
123 logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
124 DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
126 Dictionary<String, Object> properties = new Hashtable<>();
127 properties.put("shard-transaction-idle-timeout-in-minutes", "0"); // bad - must be > 0
128 properties.put("shard-journal-recovery-log-batch-size", "199");
129 properties.put("shard-transaction-commit-timeout-in-seconds", "bogus"); // bad - NaN
130 properties.put("shard-snapshot-batch-count", "212"); // good
131 properties.put("operation-timeout-in-seconds", "4"); // bad - must be >= 5
132 properties.put("shard-heartbeat-interval-in-millis", "99"); // bad - must be >= 100
133 properties.put("shard-transaction-commit-queue-capacity", "567"); // good
134 properties.put("shard-snapshot-data-threshold-percentage", "101"); // bad - must be 0-100
135 properties.put("shard-initialization-timeout-in-seconds", "-1"); // bad - must be > 0
136 properties.put("max-shard-data-change-executor-pool-size", "bogus"); // bad - NaN
137 properties.put("unknownProperty", "1"); // bad - invalid property name
139 boolean updated = introspector.update(properties);
140 assertEquals("updated", true, updated);
141 context = introspector.getContext();
143 assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout());
144 assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
145 assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds());
146 assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
147 assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_MS, context.getOperationTimeoutInMillis());
148 assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getHeartBeatInterval().length());
149 assertEquals(567, context.getShardTransactionCommitQueueCapacity());
150 assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE,
151 context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
152 assertEquals(DEFAULT_SHARD_INITIALIZATION_TIMEOUT, context.getShardInitializationTimeout());
153 assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE,
154 context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
158 public void testUpdateWithDatastoreTypeSpecificProperties() {
159 Dictionary<String, Object> properties = new Hashtable<>();
160 properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting
161 properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override
162 properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
164 properties.put("max-shard-data-change-executor-pool-size", "222"); // global setting
165 properties.put("operational.max-shard-data-change-executor-pool-size", "333"); // operational override
166 properties.put("config.max-shard-data-change-executor-pool-size", "444"); // config override
168 properties.put("persistent", "false"); // global setting
169 properties.put("operational.Persistent", "true"); // operational override
171 DatastoreContext operContext = DatastoreContext.newBuilder().
172 logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
173 DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext);
174 boolean updated = operIntrospector.update(properties);
175 assertEquals("updated", true, updated);
176 operContext = operIntrospector.getContext();
178 assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes());
179 assertEquals(true, operContext.isPersistent());
180 assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
182 DatastoreContext configContext = DatastoreContext.newBuilder()
183 .logicalStoreType(LogicalDatastoreType.CONFIGURATION).build();
184 DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext);
185 updated = configIntrospector.update(properties);
186 assertEquals("updated", true, updated);
187 configContext = configIntrospector.getContext();
189 assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes());
190 assertEquals(false, configContext.isPersistent());
191 assertEquals(444, configContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
195 public void testGetDatastoreContextForShard() {
196 Dictionary<String, Object> properties = new Hashtable<>();
197 properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting
198 properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override
199 properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
200 properties.put("topology.shard-transaction-idle-timeout-in-minutes", "55"); // global shard override
202 DatastoreContext operContext = DatastoreContext.newBuilder().
203 logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
204 DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext);
206 DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
207 assertEquals(10, shardContext.getShardTransactionIdleTimeout().toMinutes());
209 operIntrospector.update(properties);
210 operContext = operIntrospector.getContext();
211 assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes());
213 shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
214 assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
216 DatastoreContext configContext = DatastoreContext.newBuilder().
217 logicalStoreType(LogicalDatastoreType.CONFIGURATION).build();
218 DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext);
219 configIntrospector.update(properties);
220 configContext = configIntrospector.getContext();
221 assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes());
223 shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology");
224 assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
226 properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66"); // operational shard override
227 properties.put("config.topology.shard-transaction-idle-timeout-in-minutes", "77"); // config shard override
229 operIntrospector.update(properties);
230 shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
231 assertEquals(66, shardContext.getShardTransactionIdleTimeout().toMinutes());
233 configIntrospector.update(properties);
234 shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology");
235 assertEquals(77, shardContext.getShardTransactionIdleTimeout().toMinutes());
237 shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("default");
238 assertEquals(44, shardContext.getShardTransactionIdleTimeout().toMinutes());