Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
tom | a708318 | 2014-09-25 21:38:03 -0700 | [diff] [blame] | 16 | package org.onlab.nio; |
| 17 | |
| 18 | import java.io.IOException; |
| 19 | import java.nio.channels.SelectionKey; |
| 20 | import java.nio.channels.Selector; |
| 21 | import java.nio.channels.spi.AbstractSelectableChannel; |
| 22 | import java.nio.channels.spi.AbstractSelector; |
| 23 | import java.util.Set; |
| 24 | |
| 25 | /** |
| 26 | * A selector instrumented for unit tests. |
| 27 | */ |
| 28 | public 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 | } |