Merge "Startup arch - add odlparent to root pom."
[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.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS;
12 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_OPERATION_TIMEOUT_IN_SECONDS;
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.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
21
22 /**
23  * Unit tests for DatastoreContextIntrospector.
24  *
25  * @author Thomas Pantelis
26  */
27 public class DatastoreContextIntrospectorTest {
28
29     @Test
30     public void testUpdate() {
31         DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build();
32         DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
33
34         Dictionary<String, Object> properties = new Hashtable<>();
35         properties.put("shard-transaction-idle-timeout-in-minutes", "31");
36         properties.put("operation-timeout-in-seconds", "26");
37         properties.put("shard-transaction-commit-timeout-in-seconds", "100");
38         properties.put("shard-journal-recovery-log-batch-size", "199");
39         properties.put("shard-snapshot-batch-count", "212");
40         properties.put("shard-heartbeat-interval-in-millis", "101");
41         properties.put("shard-transaction-commit-queue-capacity", "567");
42         properties.put("shard-initialization-timeout-in-seconds", "82");
43         properties.put("shard-leader-election-timeout-in-seconds", "66");
44         properties.put("shard-isolated-leader-check-interval-in-millis", "123");
45         properties.put("shard-snapshot-data-threshold-percentage", "100");
46         properties.put("shard-election-timeout-factor", "21");
47         properties.put("shard-batched-modification-count", "901");
48         properties.put("transactionCreationInitialRateLimit", "200");
49         properties.put("MaxShardDataChangeExecutorPoolSize", "41");
50         properties.put("Max-Shard-Data-Change Executor-Queue Size", "1111");
51         properties.put(" max shard data change listener queue size", "2222");
52         properties.put("mAx-shaRd-data-STORE-executor-quEUe-size", "3333");
53         properties.put("persistent", "false");
54
55         boolean updated = introspector.update(properties);
56         assertEquals("updated", true, updated);
57         context = introspector.getContext();
58
59         assertEquals(31, context.getShardTransactionIdleTimeout().toMinutes());
60         assertEquals(26, context.getOperationTimeoutInSeconds());
61         assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
62         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
63         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
64         assertEquals(101, context.getShardRaftConfig().getHeartBeatInterval().length());
65         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
66         assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
67         assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
68         assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
69         assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
70         assertEquals(21, context.getShardRaftConfig().getElectionTimeoutFactor());
71         assertEquals(901, context.getShardBatchedModificationCount());
72         assertEquals(200, context.getTransactionCreationInitialRateLimit());
73         assertEquals(41, context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
74         assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize());
75         assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize());
76         assertEquals(3333, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize());
77         assertEquals(false, context.isPersistent());
78
79         properties.put("shard-transaction-idle-timeout-in-minutes", "32");
80         properties.put("operation-timeout-in-seconds", "27");
81         properties.put("shard-heartbeat-interval-in-millis", "102");
82         properties.put("shard-election-timeout-factor", "22");
83         properties.put("max-shard-data-change-executor-pool-size", "42");
84         properties.put("max-shard-data-store-executor-queue-size", "4444");
85         properties.put("persistent", "true");
86
87         updated = introspector.update(properties);
88         assertEquals("updated", true, updated);
89         context = introspector.getContext();
90
91         assertEquals(32, context.getShardTransactionIdleTimeout().toMinutes());
92         assertEquals(27, context.getOperationTimeoutInSeconds());
93         assertEquals(100, context.getShardTransactionCommitTimeoutInSeconds());
94         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
95         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
96         assertEquals(102, context.getShardRaftConfig().getHeartBeatInterval().length());
97         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
98         assertEquals(82, context.getShardInitializationTimeout().duration().toSeconds());
99         assertEquals(66, context.getShardLeaderElectionTimeout().duration().toSeconds());
100         assertEquals(123, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
101         assertEquals(100, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
102         assertEquals(22, context.getShardRaftConfig().getElectionTimeoutFactor());
103         assertEquals(200, context.getTransactionCreationInitialRateLimit());
104         assertEquals(42, context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
105         assertEquals(1111, context.getDataStoreProperties().getMaxDataChangeExecutorQueueSize());
106         assertEquals(2222, context.getDataStoreProperties().getMaxDataChangeListenerQueueSize());
107         assertEquals(4444, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize());
108         assertEquals(true, context.isPersistent());
109
110         updated = introspector.update(null);
111         assertEquals("updated", false, updated);
112
113         updated = introspector.update(new Hashtable<String, Object>());
114         assertEquals("updated", false, updated);
115     }
116
117
118     @Test
119     public void testUpdateWithInvalidValues() {
120         DatastoreContext context = DatastoreContext.newBuilder().dataStoreType("operational").build();
121         DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
122
123         Dictionary<String, Object> properties = new Hashtable<>();
124         properties.put("shard-transaction-idle-timeout-in-minutes", "0"); // bad - must be > 0
125         properties.put("shard-journal-recovery-log-batch-size", "199");
126         properties.put("shard-transaction-commit-timeout-in-seconds", "bogus"); // bad - NaN
127         properties.put("shard-snapshot-batch-count", "212"); // good
128         properties.put("operation-timeout-in-seconds", "4"); // bad - must be >= 5
129         properties.put("shard-heartbeat-interval-in-millis", "99"); // bad - must be >= 100
130         properties.put("shard-transaction-commit-queue-capacity", "567"); // good
131         properties.put("shard-snapshot-data-threshold-percentage", "101"); // bad - must be 0-100
132         properties.put("shard-initialization-timeout-in-seconds", "-1"); // bad - must be > 0
133         properties.put("max-shard-data-change-executor-pool-size", "bogus"); // bad - NaN
134         properties.put("unknownProperty", "1"); // bad - invalid property name
135
136         boolean updated = introspector.update(properties);
137         assertEquals("updated", true, updated);
138         context = introspector.getContext();
139
140         assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout());
141         assertEquals(199, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
142         assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds());
143         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
144         assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_SECONDS, context.getOperationTimeoutInSeconds());
145         assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getHeartBeatInterval().length());
146         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
147         assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE,
148                 context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
149         assertEquals(DEFAULT_SHARD_INITIALIZATION_TIMEOUT, context.getShardInitializationTimeout());
150         assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE,
151                 context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
152     }
153
154     @Test
155     public void testUpdateWithDatastoreTypeSpecificProperties() {
156         Dictionary<String, Object> properties = new Hashtable<>();
157         properties.put("shard-transaction-idle-timeout-in-minutes", "22"); // global setting
158         properties.put("operational.shard-transaction-idle-timeout-in-minutes", "33"); // operational override
159         properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
160
161         properties.put("max-shard-data-change-executor-pool-size", "222"); // global setting
162         properties.put("operational.max-shard-data-change-executor-pool-size", "333"); // operational override
163         properties.put("config.max-shard-data-change-executor-pool-size", "444"); // config override
164
165         properties.put("persistent", "false"); // global setting
166         properties.put("operational.Persistent", "true"); // operational override
167
168         DatastoreContext operContext = DatastoreContext.newBuilder().dataStoreType("operational").build();
169         DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext);
170         boolean updated = operIntrospector.update(properties);
171         assertEquals("updated", true, updated);
172         operContext = operIntrospector.getContext();
173
174         assertEquals(33, operContext.getShardTransactionIdleTimeout().toMinutes());
175         assertEquals(true, operContext.isPersistent());
176         assertEquals(333, operContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
177
178         DatastoreContext configContext = DatastoreContext.newBuilder().dataStoreType("config").build();
179         DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext);
180         updated = configIntrospector.update(properties);
181         assertEquals("updated", true, updated);
182         configContext = configIntrospector.getContext();
183
184         assertEquals(44, configContext.getShardTransactionIdleTimeout().toMinutes());
185         assertEquals(false, configContext.isPersistent());
186         assertEquals(444, configContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
187     }
188 }