Open Kilda Java Documentation
FlowDirectionHelperTest.java
Go to the documentation of this file.
1 package org.openkilda.wfm.topology.stats;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 
7 import org.junit.Rule;
8 import org.junit.Test;
9 import org.junit.rules.ExpectedException;
11 
12 import java.util.Map;
13 
15  private static final long LEGACY_FORWARD_COOKIE = 0x10400000005d803L;
16  private static final long LEGACY_REVERSE_COOKIE = 0x18400000005d803L;
17  private static final long FORWARD_COOKIE = 0x4000000000000001L;
18  private static final long REVERSE_COOKIE = 0x2000000000000001L;
19  private static final long BAD_COOKIE = 0x235789abcd432425L;
20  private static final String FLOW_ID = "f3459085345454";
21  private static final String SRC_SWITCH = "de:ad:be:ef:00:00:00:02";
22  private static final String DST_SWITCH = "de:ad:be:ef:00:00:00:04";
23 
24  private FlowDirectionHelper flowDirectionHelper;
25  private static Map<String, Object> queryMap;
26 
27  @Rule
28  public ExpectedException thrown = ExpectedException.none();
29 
30 
31  @Test
32  public void isLegacyCookieTest() {
33  assertTrue(FlowDirectionHelper.isLegacyCookie(LEGACY_FORWARD_COOKIE));
34  assertTrue(FlowDirectionHelper.isLegacyCookie(LEGACY_REVERSE_COOKIE));
35  assertFalse(FlowDirectionHelper.isLegacyCookie(FORWARD_COOKIE));
36  assertFalse(FlowDirectionHelper.isLegacyCookie(REVERSE_COOKIE));
37 
38  assertFalse(FlowDirectionHelper.isLegacyCookie(BAD_COOKIE));
39  }
40 
41  @Test
42  public void isKildaCookieTest() {
43  assertTrue(FlowDirectionHelper.isKildaCookie(FORWARD_COOKIE));
44  assertTrue(FlowDirectionHelper.isKildaCookie(REVERSE_COOKIE));
45  assertFalse(FlowDirectionHelper.isKildaCookie(LEGACY_FORWARD_COOKIE));
46  assertFalse(FlowDirectionHelper.isKildaCookie(LEGACY_REVERSE_COOKIE));
47  assertFalse(FlowDirectionHelper.isKildaCookie(BAD_COOKIE));
48  }
49 
50  @Test
51  public void getKildaDirectionTest() throws Exception {
52  assertEquals(Direction.FORWARD, FlowDirectionHelper.getKildaDirection(FORWARD_COOKIE));
53  assertEquals(Direction.REVERSE, FlowDirectionHelper.getKildaDirection(REVERSE_COOKIE));
54 
55  thrown.expect(Exception.class);
56  thrown.expectMessage(LEGACY_FORWARD_COOKIE + " is not a Kilda flow");
57  FlowDirectionHelper.getKildaDirection(LEGACY_FORWARD_COOKIE);
58  }
59 
60  @Test
61  public void getLegacyDirectionTest() throws Exception {
62  assertEquals(Direction.FORWARD, FlowDirectionHelper.getLegacyDirection(LEGACY_FORWARD_COOKIE));
63  assertEquals(Direction.REVERSE, FlowDirectionHelper.getLegacyDirection(LEGACY_REVERSE_COOKIE));
64 
65  thrown.expect(Exception.class);
66  thrown.expectMessage(FORWARD_COOKIE + " is not a legacy flow");
68  }
69 
70  @Test
71  public void findDirectionTest() throws Exception {
72  assertEquals(Direction.FORWARD, FlowDirectionHelper.findDirection(LEGACY_FORWARD_COOKIE));
73  assertEquals(Direction.REVERSE, FlowDirectionHelper.findDirection(REVERSE_COOKIE));
74 
75  thrown.expect(Exception.class);
76  thrown.expectMessage(BAD_COOKIE + " is not a Kilda flow");
78  }
79 }