aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/io
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-04-09 17:10:06 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-04-09 17:10:06 +0200
commit971f6dcd33c0788a7ca146de814ad0db9f416abf (patch)
tree67b384cda5bccf2026443c02a57775bbd4f53845 /vespajlib/src/test/java/com/yahoo/io
parentef1971a1deb1d79d120d2648d96188c77bc41003 (diff)
Remove unused nio code
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/io')
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java108
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/ListenerTestCase.java108
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java61
3 files changed, 0 insertions, 277 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java b/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java
deleted file mode 100644
index c9018224b1c..00000000000
--- a/vespajlib/src/test/java/com/yahoo/io/BlobTestCase.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.io;
-
-import org.junit.Test;
-
-import java.nio.ByteBuffer;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class BlobTestCase {
-
- @Test
- public void testEmpty() {
- Blob empty = new Blob();
- assertTrue(empty.get() != null);
- assertEquals(0, empty.get().length);
- }
-
- @Test
- public void testCopyArray() {
- byte[] d = { 1, 2, 3 };
- Blob b = new Blob(d);
- d[0] = 7;
- d[1] = 8;
- d[2] = 9;
- assertEquals(3, b.get().length);
- assertEquals(1, b.get()[0]);
- assertEquals(2, b.get()[1]);
- assertEquals(3, b.get()[2]);
- }
-
- @Test
- public void testCopyArraySubset() {
- byte[] d = { 1, 2, 3 };
- Blob b = new Blob(d, 1, 1);
- d[0] = 7;
- d[1] = 8;
- d[2] = 9;
- assertEquals(1, b.get().length);
- assertEquals(2, b.get()[0]);
- }
-
- @Test
- public void testCopyBlob() {
- byte[] d = { 1, 2, 3 };
- Blob b = new Blob(d);
- Blob x = new Blob(b);
- b.get()[1] = 4;
- assertEquals(3, x.get().length);
- assertEquals(1, x.get()[0]);
- assertEquals(4, b.get()[1]);
- assertEquals(2, x.get()[1]);
- assertEquals(3, x.get()[2]);
- }
-
- @Test
- public void testReadBuffer() {
- ByteBuffer buf = ByteBuffer.allocate(100);
- buf.put((byte)1);
- buf.put((byte)2);
- buf.put((byte)3);
- buf.flip();
- assertEquals(3, buf.remaining());
- Blob b = new Blob(buf);
- assertEquals(0, buf.remaining());
- assertEquals(3, b.get().length);
- assertEquals(1, b.get()[0]);
- assertEquals(2, b.get()[1]);
- assertEquals(3, b.get()[2]);
- }
-
- @Test
- public void testReadPartialBuffer() {
- ByteBuffer buf = ByteBuffer.allocate(100);
- buf.put((byte)1);
- buf.put((byte)2);
- buf.put((byte)3);
- buf.put((byte)4);
- buf.put((byte)5);
- buf.flip();
- assertEquals(5, buf.remaining());
- Blob b = new Blob(buf, 3);
- assertEquals(2, buf.remaining());
- assertEquals(3, b.get().length);
- assertEquals(1, b.get()[0]);
- assertEquals(2, b.get()[1]);
- assertEquals(3, b.get()[2]);
- assertEquals(4, buf.get());
- assertEquals(5, buf.get());
- assertEquals(0, buf.remaining());
- }
-
- @Test
- public void testWriteBuffer() {
- byte[] d = { 1, 2, 3 };
- Blob b = new Blob(d);
- ByteBuffer buf = ByteBuffer.allocate(100);
- b.write(buf);
- buf.flip();
- assertEquals(3, buf.remaining());
- assertEquals(1, buf.get());
- assertEquals(2, buf.get());
- assertEquals(3, buf.get());
- assertEquals(0, buf.remaining());
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/io/ListenerTestCase.java b/vespajlib/src/test/java/com/yahoo/io/ListenerTestCase.java
deleted file mode 100644
index 173197ae27c..00000000000
--- a/vespajlib/src/test/java/com/yahoo/io/ListenerTestCase.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.io;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.yahoo.collections.Tuple2;
-import com.yahoo.concurrent.Receiver;
-import com.yahoo.concurrent.Receiver.MessageState;
-
-/**
- * Test a NIO based Reactor pattern implementation, com.yahoo.io.Listener.
- *
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
- */
-public class ListenerTestCase {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- Receiver<Byte> r = new Receiver<>();
-
- private final class MockConnection implements Connection {
-
- private SocketChannel channel;
-
- MockConnection(SocketChannel channel, Listener listener) {
- this.channel = channel;
- }
-
- @Override
- public void write() throws IOException {
- }
-
- @Override
- public void read() throws IOException {
- ByteBuffer b = ByteBuffer.allocate(1);
- channel.read(b);
- b.flip();
- r.put(b.get());
- }
-
- @Override
- public void close() throws IOException {
- channel.close();
-
- }
-
- @Override
- public void connect() throws IOException {
- }
-
- @Override
- public int selectOps() {
- return SelectionKey.OP_READ;
- }
-
- @Override
- public SocketChannel socketChannel() {
- return channel;
- }
- }
-
- private final class GetConnection implements ConnectionFactory {
-
- @Override
- public Connection newConnection(SocketChannel channel, Listener listener) {
- return new MockConnection(channel, listener);
- }
- }
-
- @Test
- public final void testRun() throws IOException, InterruptedException {
- Listener l = new Listener("ListenerTestCase");
- l.listen(new GetConnection(), 0);
- l.start();
- int port = ((InetSocketAddress) l.acceptors.get(0).socket.getLocalAddress()).getPort();
- Socket s = new Socket("127.0.0.1", port);
- final byte expected = 42;
- s.getOutputStream().write(expected);
- s.getOutputStream().flush();
- s.close();
- Tuple2<MessageState, Byte> received = r.get(60 * 1000);
- l.acceptors.get(0).interrupt();
- l.acceptors.get(0).socket.close();
- l.acceptors.get(0).join();
- l.interrupt();
- l.join();
- assertTrue("Test timed out.", received.first == MessageState.VALID);
- assertEquals(expected, received.second.byteValue());
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java b/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java
deleted file mode 100644
index 7726cd7ea68..00000000000
--- a/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.io;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.zip.Deflater;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.yahoo.text.Utf8;
-
-/**
- * Check decompressor used among other things for packed summary fields.
- *
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
- */
-public class SlowInflateTestCase {
-
- private String value;
- private byte[] raw;
- private byte[] output;
- private byte[] compressed;
- private int compressedDataLength;
-
- @Before
- public void setUp() throws Exception {
- value = "000000000000000000000000000000000000000000000000000000000000000";
- raw = Utf8.toBytesStd(value);
- output = new byte[raw.length * 2];
- Deflater compresser = new Deflater();
- compresser.setInput(raw);
- compresser.finish();
- compressedDataLength = compresser.deflate(output);
- compresser.end();
- compressed = Arrays.copyOf(output, compressedDataLength);
- }
-
- @Test
- public final void test() {
- byte[] unpacked = new SlowInflate().unpack(compressed, raw.length);
- assertArrayEquals(raw, unpacked);
- }
-
- @Test
- public final void testCorruptData() {
- compressed[0] = (byte) (compressed[0] ^ compressed[1]);
- compressed[1] = (byte) (compressed[1] ^ compressed[2]);
- compressed[2] = (byte) (compressed[2] ^ compressed[3]);
- compressed[3] = (byte) (compressed[3] ^ compressed[4]);
- boolean caught = false;
- try {
- new SlowInflate().unpack(compressed, raw.length);
- } catch (RuntimeException e) {
- caught = true;
- }
- assertTrue(caught);
- }
-
-}