Add direct in-memory journal threshold
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DatastoreContextIntrospectorTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS;
14 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_OPERATION_TIMEOUT_IN_MS;
15 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
16 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD;
17 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE;
18 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
19 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
20 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
21 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import org.junit.Test;
26 import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
27 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStorePropertiesContainer;
29
30 /**
31  * Unit tests for DatastoreContextIntrospector.
32  *
33  * @author Thomas Pantelis
34  */
35 public class DatastoreContextIntrospectorTest {
36     static final AbstractDatastoreContextIntrospectorFactory INTROSPECTOR_FACTORY =
37             new DefaultDatastoreContextIntrospectorFactory(new BindingCodecContext(
38                 BindingRuntimeHelpers.createRuntimeContext(DataStorePropertiesContainer.class)));
39
40     @Test
41     public void testYangDefaults() {
42         final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance(
43                 DatastoreContext.newBuilder().shardBatchedModificationCount(2)
44                 .transactionDebugContextEnabled(true).build());
45         DatastoreContext context = introspector.getContext();
46
47         assertEquals(1000, context.getShardBatchedModificationCount());
48         assertFalse(context.isTransactionDebugContextEnabled());
49     }
50
51     @Test
52     public void testUpdate() {
53         final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL);
54
55         final Map<String, Object> properties = new HashMap<>();
56         properties.put("shard-transaction-idle-timeout-in-minutes", "31");
57         properties.put("operation-timeout-in-seconds", "26");
58         properties.put("shard-transaction-commit-timeout-in-seconds", "100");
59         properties.put("shard-journal-recovery-log-batch-size", "199");
60         properties.put("shard-snapshot-batch-count", "212");
61         properties.put("shard-heartbeat-interval-in-millis", "101");
62         properties.put("shard-transaction-commit-queue-capacity", "567");
63         properties.put("shard-initialization-timeout-in-seconds", "82");
64         properties.put("shard-leader-election-timeout-in-seconds", "66");
65         properties.put("initial-settle-timeout-multiplier", "5");
66         properties.put("recovery-snapshot-interval-seconds", "360");
67         properties.put("shard-isolated-leader-check-interval-in-millis", "123");
68         properties.put("shard-snapshot-data-threshold-percentage", "100");
69         properties.put("shard-snapshot-data-threshold", "800");
70         properties.put("shard-election-timeout-factor", "21");
71         properties.put("shard-batched-modification-count", "901");
72         properties.put("transactionCreationInitialRateLimit", "200");
73         properties.put("MaxShardDataChangeExecutorPoolSize", "41");
74         properties.put("Max-Shard-Data-Change Executor-Queue Size", "1111");
75         properties.put(" max shard data change listener queue size", "2222");
76         properties.put("mAx-shaRd-data-STORE-executor-quEUe-size", "3333");
77         properties.put("persistent", "false");
78         properties.put("initial-payload-serialized-buffer-capacity", "600");
79
80         boolean updated = introspector.update(properties);
81         assertTrue("updated", updated);
82         DatastoreContext context = introspector.getContext();
83
84         assertEquals(31, context.getShardTransactionIdleTimeout().toMinutes());
85         assertEquals(26000, context.getOperationTimeoutInMillis());
86         assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
87         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
88         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
89         assertEquals(101, context.getShardRaftConfig().getHeartBeatInterval().length());
90         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
91         assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
92         assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
93         assertEquals(5, context.getInitialSettleTimeoutMultiplier());
94         assertEquals(360, context.getShardRaftConfig().getRecoverySnapshotIntervalSeconds());
95         assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
96         assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
97         assertEquals(800, context.getShardRaftConfig().getSnapshotDataThreshold());
98         assertEquals(21, context.getShardRaftConfig().getElectionTimeoutFactor());
99         assertEquals(901, context.getShardBatchedModificationCount());
100         assertEquals(200, context.getTransactionCreationInitialRateLimit());
101         assertEquals(600, context.getInitialPayloadSerializedBufferCapacity());
102         assertFalse(context.isPersistent());
103
104         properties.put("shard-transaction-idle-timeout-in-minutes", "32");
105         properties.put("operation-timeout-in-seconds", "27");
106         properties.put("shard-heartbeat-interval-in-millis", "102");
107         properties.put("shard-election-timeout-factor", "22");
108         properties.put("initial-settle-timeout-multiplier", "6");
109         properties.put("max-shard-data-change-executor-pool-size", "42");
110         properties.put("max-shard-data-store-executor-queue-size", "4444");
111         properties.put("persistent", "true");
112
113         updated = introspector.update(properties);
114         assertTrue("updated", updated);
115         context = introspector.getContext();
116
117         assertEquals(32, context.getShardTransactionIdleTimeout().toMinutes());
118         assertEquals(27000, context.getOperationTimeoutInMillis());
119         assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
120         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
121         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
122         assertEquals(102, context.getShardRaftConfig().getHeartBeatInterval().length());
123         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
124         assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
125         assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
126         assertEquals(6, context.getInitialSettleTimeoutMultiplier());
127         assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
128         assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
129         assertEquals(800, context.getShardRaftConfig().getSnapshotDataThreshold());
130         assertEquals(22, context.getShardRaftConfig().getElectionTimeoutFactor());
131         assertEquals(200, context.getTransactionCreationInitialRateLimit());
132         assertTrue(context.isPersistent());
133
134         updated = introspector.update(null);
135         assertFalse("updated", updated);
136
137         updated = introspector.update(new HashMap<>());
138         assertFalse("updated", updated);
139     }
140
141
142     @Test
143     public void testUpdateWithInvalidValues() {
144         final DatastoreContextIntrospector introspector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL);
145
146         final Map<String, Object> properties = new HashMap<>();
147         properties.put("shard-transaction-idle-timeout-in-minutes", "0"); // bad - must be > 0
148         properties.put("shard-journal-recovery-log-batch-size", "199");
149         properties.put("shard-transaction-commit-timeout-in-seconds", "bogus"); // bad - NaN
150         properties.put("shard-snapshot-batch-count", "212"); // good
151         properties.put("operation-timeout-in-seconds", "4"); // bad - must be >= 5
152         properties.put("shard-heartbeat-interval-in-millis", "99"); // bad - must be >= 100
153         properties.put("shard-transaction-commit-queue-capacity", "567"); // good
154         properties.put("shard-snapshot-data-threshold-percentage", "101"); // bad - must be 0-100
155         properties.put("shard-snapshot-data-threshold", "-1"); // bad - must be > 0
156         properties.put("shard-initialization-timeout-in-seconds", "-1"); // bad - must be > 0
157         properties.put("max-shard-data-change-executor-pool-size", "bogus"); // bad - NaN
158         properties.put("unknownProperty", "1"); // bad - invalid property name
159
160         final boolean updated = introspector.update(properties);
161         assertTrue("updated", updated);
162         DatastoreContext context = introspector.getContext();
163
164         assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout());
165         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
166         assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds());
167         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
168         assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_MS, context.getOperationTimeoutInMillis());
169         assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS,
170                 context.getShardRaftConfig().getHeartBeatInterval().length());
171         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
172         assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE,
173                 context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
174         assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD, context.getShardRaftConfig().getSnapshotDataThreshold());
175         assertEquals(DEFAULT_SHARD_INITIALIZATION_TIMEOUT, context.getShardInitializationTimeout());
176     }
177
178     @Test
179     public void testUpdateWithDatastoreTypeSpecificProperties() {
180         final Map<String, Object> properties = new HashMap<>();
181         properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting
182         properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override
183         properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
184
185         properties.put("max-shard-data-change-executor-pool-size", "222"); // global setting
186         properties.put("operational.max-shard-data-change-executor-pool-size", "333"); // operational override
187         properties.put("config.max-shard-data-change-executor-pool-size", "444"); // config override
188
189         properties.put("persistent", "false"); // global setting
190         properties.put("operational.Persistent", "true"); // operational override
191
192         final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL);
193         boolean updated = operIntrospector.update(properties);
194         assertTrue("updated", updated);
195         DatastoreContext operContext = operIntrospector.getContext();
196
197         assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes());
198         assertTrue(operContext.isPersistent());
199
200         final DatastoreContextIntrospector configIntrospector = INTROSPECTOR_FACTORY.newInstance(CONFIGURATION);
201         updated = configIntrospector.update(properties);
202         assertTrue("updated", updated);
203         DatastoreContext configContext = configIntrospector.getContext();
204
205         assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes());
206         assertFalse(configContext.isPersistent());
207     }
208
209     @Test
210     public void testGetDatastoreContextForShard() {
211         final Map<String, Object> properties = new HashMap<>();
212         properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting
213         properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override
214         properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
215         properties.put("topology.shard-transaction-idle-timeout-in-minutes", "55"); // global shard override
216         properties.put("config.topology.persistent", "false"); // per-shard config override
217
218         final DatastoreContextIntrospector operIntrospector = INTROSPECTOR_FACTORY.newInstance(OPERATIONAL);
219
220         DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
221         assertEquals(10, shardContext.getShardTransactionIdleTimeout().toMinutes());
222
223         operIntrospector.update(properties);
224         DatastoreContext operContext = operIntrospector.getContext();
225         assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes());
226
227         shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
228         assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
229
230         final DatastoreContextIntrospector configIntrospector = INTROSPECTOR_FACTORY.newInstance(CONFIGURATION);
231         configIntrospector.update(properties);
232         DatastoreContext configContext = configIntrospector.getContext();
233         assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes());
234
235         shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology");
236         assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
237         assertFalse(shardContext.isPersistent());
238
239         // operational shard override
240         properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66");
241         // config shard override
242         properties.put("config.topology.shard-transaction-idle-timeout-in-minutes", "77");
243
244         operIntrospector.update(properties);
245         shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
246         assertEquals(66, shardContext.getShardTransactionIdleTimeout().toMinutes());
247
248         configIntrospector.update(properties);
249         shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology");
250         assertEquals(77, shardContext.getShardTransactionIdleTimeout().toMinutes());
251
252         shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("default");
253         assertEquals(44, shardContext.getShardTransactionIdleTimeout().toMinutes());
254         assertTrue(shardContext.isPersistent());
255     }
256 }

©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.