blob: cf5b2bb9be6860423e0f6aba509fab0f4bdde25c [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
toma7083182014-09-25 21:38:03 -070016package org.onlab.nio;
17
18import java.io.IOException;
19import java.nio.channels.SelectionKey;
20import java.nio.channels.Selector;
21import java.nio.channels.spi.AbstractSelectableChannel;
22import java.nio.channels.spi.AbstractSelector;
23import java.util.Set;
24
25/**
26 * A selector instrumented for unit tests.
27 */
28public class MockSelector extends AbstractSelector {
29
30 int wakeUpCount = 0;
31
32 /**
33 * Creates a mock selector, specifying null as the SelectorProvider.
34 */
35 public MockSelector() {
36 super(null);
37 }
38
39 @Override
40 public String toString() {
41 return "{MockSelector: wake=" + wakeUpCount + "}";
42 }
43
44 @Override
45 protected void implCloseSelector() throws IOException {
46 }
47
48 @Override
49 protected SelectionKey register(AbstractSelectableChannel ch, int ops,
50 Object att) {
51 return null;
52 }
53
54 @Override
55 public Set<SelectionKey> keys() {
56 return null;
57 }
58
59 @Override
60 public Set<SelectionKey> selectedKeys() {
61 return null;
62 }
63
64 @Override
65 public int selectNow() throws IOException {
66 return 0;
67 }
68
69 @Override
70 public int select(long timeout) throws IOException {
71 return 0;
72 }
73
74 @Override
75 public int select() throws IOException {
76 return 0;
77 }
78
79 @Override
80 public Selector wakeup() {
81 wakeUpCount++;
82 return null;
83 }
84
85}