blob: 535a09544deee9757eda5235dba1884d3c9dc7a7 [file] [log] [blame]
Ray Milkey24e60b32015-08-12 11:39:54 -07001/*
Sbhat35ee3132c2017-07-05 14:17:34 -07002 * Copyright 2017-present Open Networking Laboratory
Ray Milkey24e60b32015-08-12 11:39:54 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.flowobjective.impl;
17
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.net.behaviour.DefaultNextGroup;
22import org.onosproject.net.behaviour.NextGroup;
23import org.onosproject.net.flowobjective.FlowObjectiveStore;
24import org.onosproject.store.service.TestStorageService;
25
26import com.google.common.base.Charsets;
Sbhat35ee3132c2017-07-05 14:17:34 -070027
28import java.util.Collections;
29
Ray Milkey24e60b32015-08-12 11:39:54 -070030import static org.hamcrest.MatcherAssert.assertThat;
Sbhat35ee3132c2017-07-05 14:17:34 -070031import static org.junit.Assert.assertEquals;
Ray Milkey24e60b32015-08-12 11:39:54 -070032import static org.hamcrest.Matchers.*;
Sbhat35ee3132c2017-07-05 14:17:34 -070033import static org.junit.Assert.assertFalse;
34import static org.junit.Assert.assertTrue;
Ray Milkey24e60b32015-08-12 11:39:54 -070035
36/**
37 * Unit tests for distributed flow objective store.
38 */
39public class DistributedFlowObjectiveStoreTest {
40 DistributedFlowObjectiveStore storeImpl;
41 FlowObjectiveStore store;
42
43 @Before
44 public void setUp() {
45 storeImpl = new DistributedFlowObjectiveStore();
46 storeImpl.storageService = new TestStorageService();
47 storeImpl.activate();
48 store = storeImpl;
49 }
50
51 @After
52 public void tearDown() {
53 storeImpl.deactivate();
54 }
55
56 @Test
57 public void testFlowObjectiveStore() {
Sbhat35ee3132c2017-07-05 14:17:34 -070058 NextGroup group1 = new DefaultNextGroup("1".getBytes(Charsets.US_ASCII));
Ray Milkey24e60b32015-08-12 11:39:54 -070059 NextGroup group2 = new DefaultNextGroup("2".getBytes(Charsets.US_ASCII));
60 int group1Id = store.allocateNextId();
61 int group2Id = store.allocateNextId();
62
63 NextGroup group1add = store.getNextGroup(group1Id);
64 assertThat(group1add, nullValue());
Sbhat35ee3132c2017-07-05 14:17:34 -070065 NextGroup dif = store.getNextGroup(3);
66 assertThat(dif, is(nullValue()));
Ray Milkey24e60b32015-08-12 11:39:54 -070067
Sbhat35ee3132c2017-07-05 14:17:34 -070068
69 store.putNextGroup(group1Id, group1);
Ray Milkey24e60b32015-08-12 11:39:54 -070070 store.putNextGroup(group2Id, group2);
71 NextGroup group2Query = store.getNextGroup(group2Id);
72 assertThat(group2Query.data(), is(group2.data()));
Sbhat35ee3132c2017-07-05 14:17:34 -070073 assertTrue(store.getAllGroups().containsKey(group2Id));
74 assertTrue(store.getAllGroups().containsKey(group1Id));
75
76 store.removeNextGroup(group2Id);
77 assertTrue(store.getAllGroups().containsKey(group1Id));
78 assertFalse(store.getAllGroups().containsKey(group2Id));
79 store.removeNextGroup(group1Id);
80 assertEquals(store.getAllGroups(), Collections.emptyMap());
Ray Milkey24e60b32015-08-12 11:39:54 -070081 }
Sbhat35ee3132c2017-07-05 14:17:34 -070082}