2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowplugin.impl.configuration;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.when;
18 import com.google.common.collect.ImmutableMap;
19 import java.util.Hashtable;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.runners.MockitoJUnitRunner;
26 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener;
27 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
28 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
33 @RunWith(MockitoJUnitRunner.class)
34 public class ConfigurationServiceFactoryImplTest {
35 private static final int CONFIG_PROP_COUNT = 23;
36 private static final boolean IS_STATISTICS_POLLING_ON = true;
37 private static final int BARRIER_COUNT_LIMIT = 2000;
38 private static final long BARRIER_INTERVAL_TIMEOUT_LIMIT = 3000;
39 private static final long ECHO_REPLY_TIMEOUT = 4000;
40 private static final boolean ENABLE_FLOW_REMOVED_NOTIFICATION = true;
41 private static final boolean SKIP_TABLE_FEATURES = true;
42 private static final long BASIC_TIMER_DELAY = 2690;
43 private static final long MAXIMUM_TIMER_DELAY = 3679;
44 private static final boolean SWITCH_FEATURES_MANDATORY = false;
45 private static final boolean IS_STATISTICS_RPC_ENABLED = false;
46 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = true;
47 private static final int RPC_REQUESTS_QUOTA = 2500;
48 private static final long GLOBAL_NOTIFICATION_QUOTA = 9000;
49 private static final int THREAD_POOL_MIN_THREADS = 3;
50 private static final int THREAD_POOL_MIN_THREADS_UPDATE = 4;
51 private static final int THREAD_POOL_MAX_THREADS = 1000;
52 private static final long THREAD_POOL_TIMEOUT = 60;
53 private static final int DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = 0;
56 private OpenflowProviderConfig config;
59 private ConfigurationListener configurationListener;
61 private ConfigurationService configurationService;
64 public void setUp() throws Exception {
65 when(config.isIsStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
66 when(config.isIsFlowStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
67 when(config.isIsTableStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
68 when(config.isIsFlowStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
69 when(config.isIsGroupStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
70 when(config.isIsMeterStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
71 when(config.isIsQueueStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
72 when(config.isIsPortStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
73 when(config.getBarrierCountLimit()).thenReturn(new NonZeroUint16Type(BARRIER_COUNT_LIMIT));
74 when(config.getBarrierIntervalTimeoutLimit()).thenReturn(new NonZeroUint32Type(BARRIER_INTERVAL_TIMEOUT_LIMIT));
75 when(config.getEchoReplyTimeout()).thenReturn(new NonZeroUint32Type(ECHO_REPLY_TIMEOUT));
76 when(config.isEnableFlowRemovedNotification()).thenReturn(ENABLE_FLOW_REMOVED_NOTIFICATION);
77 when(config.isSkipTableFeatures()).thenReturn(SKIP_TABLE_FEATURES);
78 when(config.getBasicTimerDelay()).thenReturn(new NonZeroUint32Type(BASIC_TIMER_DELAY));
79 when(config.getMaximumTimerDelay()).thenReturn(new NonZeroUint32Type(MAXIMUM_TIMER_DELAY));
80 when(config.isSwitchFeaturesMandatory()).thenReturn(SWITCH_FEATURES_MANDATORY);
81 when(config.isIsStatisticsRpcEnabled()).thenReturn(IS_STATISTICS_RPC_ENABLED);
82 when(config.isUseSingleLayerSerialization()).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
83 when(config.getRpcRequestsQuota()).thenReturn(new NonZeroUint16Type(RPC_REQUESTS_QUOTA));
84 when(config.getGlobalNotificationQuota()).thenReturn(GLOBAL_NOTIFICATION_QUOTA);
85 when(config.getThreadPoolMinThreads()).thenReturn(THREAD_POOL_MIN_THREADS);
86 when(config.getThreadPoolMaxThreads()).thenReturn(new NonZeroUint16Type(THREAD_POOL_MAX_THREADS));
87 when(config.getThreadPoolTimeout()).thenReturn(THREAD_POOL_TIMEOUT);
88 when(config.getDeviceConnectionRateLimitPerMin()).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
90 final Map<String, String> properties = new Hashtable<>();
91 properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(),
92 Boolean.toString(IS_STATISTICS_POLLING_ON));
94 configurationService = new ConfigurationServiceFactoryImpl().newInstance(config);
95 configurationService.update(properties);
99 public void update() throws Exception {
100 final int tpMinThreads = configurationService
101 .getProperty(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), Integer::valueOf);
103 configurationService.update(ImmutableMap
104 .<String, String>builder()
105 .put(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), String
106 .valueOf(THREAD_POOL_MIN_THREADS_UPDATE))
109 final int tpMinThreadsNew = configurationService
110 .getProperty(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), Integer::valueOf);
112 assertNotEquals(tpMinThreadsNew, tpMinThreads);
113 assertEquals(tpMinThreadsNew, THREAD_POOL_MIN_THREADS_UPDATE);
117 public void getProperty() throws Exception {
118 final int tpMaxThreads = configurationService
119 .getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf);
121 assertEquals(THREAD_POOL_MAX_THREADS, tpMaxThreads);
125 public void registerListener() throws Exception {
126 configurationService.registerListener(configurationListener);
127 verify(configurationListener, times(CONFIG_PROP_COUNT)).onPropertyChanged(any(), any());
130 @Test(expected = NumberFormatException.class)
131 public void close() throws Exception {
132 configurationService.close();
133 configurationService.getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf);