BUG-1075: ingress back pressure
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / util / PollableQueuesZipperTest.java
1 /**
2  * Copyright (c) 2014 Cisco 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.openflowplugin.openflow.md.util;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Queue;
13 import java.util.concurrent.LinkedBlockingQueue;
14
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.openflow.md.util.PollableQueuesZipper;
18
19 import com.google.common.collect.Lists;
20
21 /**
22  * test for {@link PollableQueuesZipper}
23  */
24 public class PollableQueuesZipperTest {
25
26     /**
27      * Test method for {@link org.opendaylight.openflowplugin.openflow.md.util.PollableQueuesZipper#poll()}.
28      */
29     @Test
30     public void testPoll() {
31         Queue<String> l1 = new LinkedBlockingQueue<String>(Lists.newArrayList("1", "2", "3"));
32         Queue<String> l2 = new LinkedBlockingQueue<String>(Lists.newArrayList("a", "b", "c", "d"));
33         Queue<String> l3 = new LinkedBlockingQueue<String>(Lists.newArrayList("A", "B"));
34
35         PollableQueuesZipper<String> zipper = new PollableQueuesZipper<>();
36         zipper.addSource(l1);
37         zipper.addSource(l2);
38         zipper.addSource(l3);
39
40         String[] expected = new String[] {
41                 "1", "a", "A", "2", "b", "B", "3", "c", "d", null, "XXX"
42         };
43         List<String> result = new ArrayList<>();
44         while (true) {
45             String data = zipper.poll();
46             result.add(data);
47             if (data == null) {
48                 break;
49             }
50         }
51         l1.offer("XXX");
52         result.add(zipper.poll());
53         Assert.assertArrayEquals(expected, result.toArray());
54     }
55
56 }