diff --git a/test/dorkbox/network/not-fixed/ChunkedDataIdleTest.java b/test/dorkbox/network/not-fixed/ChunkedDataIdleTest.java deleted file mode 100644 index fb3998ef..00000000 --- a/test/dorkbox/network/not-fixed/ChunkedDataIdleTest.java +++ /dev/null @@ -1,346 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Arrays; - -import org.junit.Test; - -import dorkbox.network.PingPongTest.TYPE; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.idle.IdleBridge; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -@SuppressWarnings("Duplicates") -public class ChunkedDataIdleTest extends BaseTest { - private volatile boolean success = false; - - enum ConnectionType { - TCP, - UDP - } - - // have to test sending objects - @Test - public void SendTcp() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - System.err.println("-- TCP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.TCP); - } - - // have to test sending objects - @Test - public - void SendUdp() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - System.err.println("-- UDP"); - Configuration configuration = new Configuration(); - // configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.UDP); - } - - // have to test sending objects - @Test - public void SendTcpUdp_Udp() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - System.err.println("-- UDP (with TCP connection alive)"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.UDP); - } - - // have to test sending objects - @Test - public void SendTcpUdp_Tcp() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - - System.err.println("-- TCP/UDP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.TCP); - } - - - - private void sendObject(final Data mainData, Configuration configuration, final ConnectionType type) - throws SecurityException, IOException { - success = false; - - Server server = new Server(configuration); - addEndPoint(server); - server.setIdleTimeout(10); - server.bind(false); - server.listeners().add(new Listener.OnConnected() { - - @Override - public void connected (Connection connection) { - Data data = new Data(); - populateData(data); - - IdleBridge sendOnIdle = connection.sendOnIdle(data); - - switch (type) { - case TCP: sendOnIdle.TCP(); break; - case UDP: sendOnIdle.UDP(); break; - } - } - }); - - // ---- - - Client client = new Client(configuration); - client.setIdleTimeout(10); - addEndPoint(client); - client.listeners().add(new Listener.OnMessageReceived() { - @Override - public void received(Connection connection, Data object) { - if (mainData.equals(object)) { - ChunkedDataIdleTest.this.success = true; - } - - System.err.println("finished!"); - stopEndPoints(); - } - }); - - client.connect(5000); - - waitForThreads(); - if (!this.success) { - fail(); - } - } - - - private void populateData(Data data) { - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < 3000; i++) { - buffer.append('a'); - } - data.string = buffer.toString(); - - data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"}; - data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.shorts = new short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; - - data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; - data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - - data.booleans = new boolean[] {true, false}; - data.Ints = new Integer[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.Shorts = new Short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.Floats = new Float[] {0f, -0f, 1f, -1f, 123456f, -123456f, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; - data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.Longs = new Long[] {0L, -0L, 1L, -1L, 123456L, -123456L, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; - data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - data.Booleans = new Boolean[] {true, false}; - } - - private void register (SerializationManager manager) { - manager.register(int[].class); - manager.register(short[].class); - manager.register(float[].class); - manager.register(double[].class); - manager.register(long[].class); - manager.register(byte[].class); - manager.register(char[].class); - manager.register(boolean[].class); - manager.register(String[].class); - manager.register(Integer[].class); - manager.register(Short[].class); - manager.register(Float[].class); - manager.register(Double[].class); - manager.register(Long[].class); - manager.register(Byte[].class); - manager.register(Character[].class); - manager.register(Boolean[].class); - manager.register(Data.class); - manager.register(TYPE.class); - } - - @SuppressWarnings("WeakerAccess") - static public class Data { - public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public double[] doubles; - public long[] longs; - public byte[] bytes; - public char[] chars; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Double[] Doubles; - public Long[] Longs; - public Byte[] Bytes; - public Character[] Chars; - public Boolean[] Booleans; - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(this.Booleans); - result = prime * result + Arrays.hashCode(this.Bytes); - result = prime * result + Arrays.hashCode(this.Chars); - result = prime * result + Arrays.hashCode(this.Doubles); - result = prime * result + Arrays.hashCode(this.Floats); - result = prime * result + Arrays.hashCode(this.Ints); - result = prime * result + Arrays.hashCode(this.Longs); - result = prime * result + Arrays.hashCode(this.Shorts); - result = prime * result + Arrays.hashCode(this.booleans); - result = prime * result + Arrays.hashCode(this.bytes); - result = prime * result + Arrays.hashCode(this.chars); - result = prime * result + Arrays.hashCode(this.doubles); - result = prime * result + Arrays.hashCode(this.floats); - result = prime * result + Arrays.hashCode(this.ints); - result = prime * result + Arrays.hashCode(this.longs); - result = prime * result + Arrays.hashCode(this.shorts); - result = prime * result + (this.string == null ? 0 : this.string.hashCode()); - result = prime * result + Arrays.hashCode(this.strings); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Data other = (Data) obj; - if (!Arrays.equals(this.Booleans, other.Booleans)) { - return false; - } - if (!Arrays.equals(this.Bytes, other.Bytes)) { - return false; - } - if (!Arrays.equals(this.Chars, other.Chars)) { - return false; - } - if (!Arrays.equals(this.Doubles, other.Doubles)) { - return false; - } - if (!Arrays.equals(this.Floats, other.Floats)) { - return false; - } - if (!Arrays.equals(this.Ints, other.Ints)) { - return false; - } - if (!Arrays.equals(this.Longs, other.Longs)) { - return false; - } - if (!Arrays.equals(this.Shorts, other.Shorts)) { - return false; - } - if (!Arrays.equals(this.booleans, other.booleans)) { - return false; - } - if (!Arrays.equals(this.bytes, other.bytes)) { - return false; - } - if (!Arrays.equals(this.chars, other.chars)) { - return false; - } - if (!Arrays.equals(this.doubles, other.doubles)) { - return false; - } - if (!Arrays.equals(this.floats, other.floats)) { - return false; - } - if (!Arrays.equals(this.ints, other.ints)) { - return false; - } - if (!Arrays.equals(this.longs, other.longs)) { - return false; - } - if (!Arrays.equals(this.shorts, other.shorts)) { - return false; - } - if (this.string == null) { - if (other.string != null) { - return false; - } - } else if (!this.string.equals(other.string)) { - return false; - } - if (!Arrays.equals(this.strings, other.strings)) { - return false; - } - return true; - } - - @Override - public String toString () { - return "Data"; - } - } -} diff --git a/test/dorkbox/network/not-fixed/ClientSendTest.java b/test/dorkbox/network/not-fixed/ClientSendTest.java deleted file mode 100644 index 0f6a3267..00000000 --- a/test/dorkbox/network/not-fixed/ClientSendTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -public -class ClientSendTest extends BaseTest { - - private AtomicBoolean checkPassed = new AtomicBoolean(false); - - @Test - public - void sendDataFromClientClass() throws SecurityException, IOException { - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, AMessage object) { - System.err.println("Server received message from client. Bouncing back."); - connection.send() - .TCP(object); - } - }); - - Client client = new Client(configuration); - addEndPoint(client); - client.connect(5000); - - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, AMessage object) { - ClientSendTest.this.checkPassed.set(true); - stopEndPoints(); - } - }); - - client.send() - .TCP(new AMessage()); - - waitForThreads(); - - if (!this.checkPassed.get()) { - fail("Client and server failed to send messages!"); - } - } - - private static - void register(SerializationManager manager) { - manager.register(AMessage.class); - } - - public static - class AMessage { - public - AMessage() { - } - } -} diff --git a/test/dorkbox/network/not-fixed/ConnectionTest.java b/test/dorkbox/network/not-fixed/ConnectionTest.java deleted file mode 100644 index 07b04c9b..00000000 --- a/test/dorkbox/network/not-fixed/ConnectionTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Assert; -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.Listener.OnConnected; -import dorkbox.network.connection.Listener.OnDisconnected; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -public -class ConnectionTest extends BaseTest { - private AtomicInteger successCount; - - @Test - public - void connectLocal() throws SecurityException, IOException { - System.out.println("---- " + "Local"); - successCount = new AtomicInteger(0); - - Configuration configuration = new Configuration(); - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - startServer(configuration); - startClient(configuration); - - waitForThreads(10); - Assert.assertEquals(6, successCount.get()); - } - - @Test - public - void connectTcp() throws SecurityException, IOException { - System.out.println("---- " + "TCP"); - successCount = new AtomicInteger(0); - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - startServer(configuration); - - configuration.host = host; - startClient(configuration); - - waitForThreads(10); - Assert.assertEquals(6, successCount.get()); - } - - @Test - public - void connectUdp() throws SecurityException, IOException { - System.out.println("---- " + "UDP"); - successCount = new AtomicInteger(0); - - Configuration configuration = new Configuration(); - configuration.udpPort = udpPort; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - startServer(configuration); - - configuration.host = host; - startClient(configuration); - - waitForThreads(10); - Assert.assertEquals(6, successCount.get()); - } - - @Test - public - void connectTcpUdp() throws SecurityException, IOException { - System.out.println("---- " + "TCP UDP"); - successCount = new AtomicInteger(0); - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - startServer(configuration); - - configuration.host = host; - startClient(configuration); - - waitForThreads(10); - Assert.assertEquals(6, successCount.get()); - } - - private - Server startServer(final Configuration configuration) throws SecurityException { - final Server server = new Server(configuration); - - addEndPoint(server); - - server.bind(false); - server.listeners() - .add(new OnConnected() { - @Override - public - void connected(final Connection connection) { - successCount.getAndIncrement(); - } - }) - .add(new OnDisconnected() { - @Override - public - void disconnected(Connection connection) { - successCount.getAndIncrement(); - } - }) - .add(new Listener.OnMessageReceived() { - @Override - public void received(Connection connection, Object message) { - System.err.println("Received message from client: " + message.getClass().getSimpleName()); - - successCount.getAndIncrement(); - if (configuration.tcpPort > 0) { - connection.send() - .TCP(message); - } - else { - connection.send() - .UDP(message); - } - } - }); - - return server; - } - - private - Client startClient(final Configuration configuration) throws SecurityException, IOException { - Client client; - if (configuration != null) { - client = new Client(configuration); - } - else { - client = new Client(); - } - addEndPoint(client); - - client.listeners() - .add(new OnConnected() { - @Override - public - void connected(final Connection connection) { - successCount.getAndIncrement(); - } - }) - .add(new OnDisconnected() { - @Override - public - void disconnected(Connection connection) { - successCount.getAndIncrement(); - } - }) - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, Object message) { - System.err.println("Received message from server: " + message.getClass() - .getSimpleName()); - System.err.println("Now disconnecting!"); - successCount.getAndIncrement(); - - stopEndPoints(); - } - }); - client.connect(5000); - - if (configuration.tcpPort > 0) { - client.send() - .TCP(new BMessage()); - } - else { - client.send() - .UDP(new BMessage()); - } - - return client; - } - - private - void register(SerializationManager manager) { - manager.register(BMessage.class); - } - - public static - class BMessage { - public - BMessage() { - } - } -} diff --git a/test/dorkbox/network/not-fixed/DisconnectReconnectTest.java b/test/dorkbox/network/not-fixed/DisconnectReconnectTest.java deleted file mode 100644 index 41922418..00000000 --- a/test/dorkbox/network/not-fixed/DisconnectReconnectTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2016 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.util.exceptions.SecurityException; - -public -class DisconnectReconnectTest extends BaseTest { - private final Timer timer = new Timer(); - - @Test - public - void reconnect() throws SecurityException, IOException { - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - - - Server server = new Server(configuration); - - server.bind(false); - addEndPoint(server); - - server.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - System.out.println("Disconnecting after 2 seconds."); - timer.schedule(new TimerTask() { - @Override - public - void run() { - System.out.println("Disconnecting...."); - connection.close(); - } - }, 2000); - } - }); - - // ---- - - final AtomicInteger reconnectCount = new AtomicInteger(); - final Client client = new Client(configuration); - addEndPoint(client); - client.listeners() - .add(new Listener.OnDisconnected() { - @Override - public - void disconnected(Connection connection) { - int count = reconnectCount.getAndIncrement(); - if (count == 3) { - System.out.println("Shutting down"); - stopEndPoints(); - } - else { - System.out.println("Reconnecting: " + count); - try { - client.reconnect(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - }); - client.connect(5000); - - waitForThreads(); - - System.err.println("Connection count (after reconnecting) is: " + reconnectCount.get()); - assertEquals(4, reconnectCount.get()); - } -} diff --git a/test/dorkbox/network/not-fixed/DiscoverHostTest.java b/test/dorkbox/network/not-fixed/DiscoverHostTest.java deleted file mode 100644 index ec518a66..00000000 --- a/test/dorkbox/network/not-fixed/DiscoverHostTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.pipeline.discovery.BroadcastResponse; -import dorkbox.util.exceptions.SecurityException; - -public -class DiscoverHostTest extends BaseTest { - volatile boolean connected = false; - - @Test - public - void broadcast() throws SecurityException, IOException { - - Configuration configuration = new Configuration(); - // configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - // ---- - - BroadcastResponse host = Broadcast.discoverHost(udpPort, 2000); - if (host == null) { - stopEndPoints(); - fail("No servers found. Maybe you are behind a VPN service or your network is mis-configured?"); - return; - } - - // run it twice... - - host = Broadcast.discoverHost(udpPort, 2000); - if (host == null) { - stopEndPoints(); - fail("No servers found. Maybe you are behind a VPN service or your network is mis-configured?"); - return; - } - - Client client = new Client(configuration); - addEndPoint(client); - client.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - DiscoverHostTest.this.connected = true; - stopEndPoints(); - } - }); - client.connect(2000); - - waitForThreads(20); - - if (!this.connected) { - fail("Unable to connect to server."); - } - } -} diff --git a/test/dorkbox/network/not-fixed/FirewallTest.java b/test/dorkbox/network/not-fixed/FirewallTest.java deleted file mode 100644 index 816cb55a..00000000 --- a/test/dorkbox/network/not-fixed/FirewallTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -public -class FirewallTest extends BaseTest { - - private AtomicBoolean checkPassed = new AtomicBoolean(false); - - @Test - public - void sendDataFromClientClass() throws SecurityException, IOException { - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - // configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - Server server = new Server(configuration); - - // server.addIpFilter(Server.permitLocalHostRule); - // server.addIpFilter(new IpSubnetFilterRule(NetUtil.LOCALHOST, 32, IpFilterRuleType.REJECT)); - - // server.addConnectionTypeFilter(new ConnectionRule(NetUtil.LOCALHOST, 32, ConnectionType.COMPRESS_AND_ENCRYPT)); - - addEndPoint(server); - server.bind(false); - - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, AMessage object) { - System.err.println("Server received message from client. Bouncing back."); - connection.send(object); - } - }); - - Client client = new Client(configuration); - addEndPoint(client); - client.connect(5000); - - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, AMessage object) { - FirewallTest.this.checkPassed.set(true); - stopEndPoints(); - } - }); - - client.send(new AMessage()); - - waitForThreads(); - - if (!this.checkPassed.get()) { - fail("Client and server failed to send messages!"); - } - } - - private static - void register(SerializationManager manager) { - manager.register(AMessage.class); - } - - public static - class AMessage { - public - AMessage() { - } - } -} diff --git a/test/dorkbox/network/not-fixed/IdleTest.java b/test/dorkbox/network/not-fixed/IdleTest.java deleted file mode 100644 index 236c90cc..00000000 --- a/test/dorkbox/network/not-fixed/IdleTest.java +++ /dev/null @@ -1,442 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Arrays; - -import org.junit.Test; - -import dorkbox.network.PingPongTest.TYPE; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -@SuppressWarnings({"rawtypes"}) -public -class IdleTest extends BaseTest { - private volatile boolean success = false; - - - enum ConnectionType { - TCP, - UDP - } - - @Test - public - void InputStreamSenderTCP() throws SecurityException, IOException { - final int largeDataSize = 12345; - - System.err.println("-- TCP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(false, false, null); - - streamSpecificType(largeDataSize, configuration, ConnectionType.TCP); - } - - @Test - public - void InputStreamSenderUDP() throws SecurityException, IOException { - final int largeDataSize = 12345; - - System.err.println("-- UDP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(false, false, null); - - streamSpecificType(largeDataSize, configuration, ConnectionType.UDP); - } - - - - // have to test sending objects - @Test - public - void ObjectSenderTCP() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - System.err.println("-- TCP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.TCP); - } - - // have to test sending objects - @Test - public - void ObjectSenderUDP() throws SecurityException, IOException { - final Data mainData = new Data(); - populateData(mainData); - - - System.err.println("-- UDP"); - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - sendObject(mainData, configuration, ConnectionType.TCP); - } - - private - void sendObject(final Data mainData, Configuration configuration, final ConnectionType type) - throws SecurityException, IOException { - - Server server = new Server(configuration); - addEndPoint(server); - server.setIdleTimeout(100); - server.bind(false); - server.listeners() - .add(new Listener.OnConnected() { - - @Override - public - void connected(Connection connection) { - IdleBridge sendOnIdle = connection.sendOnIdle(mainData); - - switch (type) { - case TCP: - sendOnIdle.TCP(); - break; - case UDP: - sendOnIdle.UDP(); - break; - } - } - }); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, Data object) { - if (mainData.equals(object)) { - IdleTest.this.success = true; - } - - System.err.println("finished!"); - stopEndPoints(); - } - }); - - client.connect(5000); - - waitForThreads(); - if (!this.success) { - fail(); - } - } - - - - private - void streamSpecificType(final int largeDataSize, Configuration configuration, final ConnectionType type) - throws SecurityException, IOException { - Server server = new Server(configuration); - addEndPoint(server); - server.setIdleTimeout(100); - server.bind(false); - server.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - ByteArrayOutputStream output = new ByteArrayOutputStream(largeDataSize); - for (int i = 0; i < largeDataSize; i++) { - output.write(i); - } - - ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); - - IdleListener listener = null; - switch (type) { - case TCP: - listener = new IdleListenerTCP(); - break; - case UDP: - listener = new IdleListenerUDP(); - break; - } - - - // Send data in 512 byte chunks. - IdleBridge sendOnIdle = connection.sendOnIdle(new InputStreamSender(listener, input, 512) { - @Override - protected - void start() { - // Normally would send an object so the receiving side knows how to handle the chunks we are about to send. - System.err.println("starting"); - } - - @Override - protected - byte[] onNext(byte[] bytes) { - //System.out.println("sending " + bytes.length); - return bytes; // Normally would wrap the byte[] with an object so the receiving side knows how to handle it. - } - }); - - switch (type) { - case TCP: - sendOnIdle.TCP(); - break; - case UDP: - sendOnIdle.UDP(); - break; - } - } - }); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - client.listeners() - .add(new Listener.OnMessageReceived() { - int total; - - @Override - public - void received(Connection connection, byte[] object) { - int length = object.length; - //System.err.println("received " + length); - this.total += length; - if (this.total == largeDataSize) { - IdleTest.this.success = true; - System.err.println("finished!"); - stopEndPoints(); - } - } - }); - - client.connect(5000); - - waitForThreads(); - if (!this.success) { - fail(); - } - } - - - private static - void populateData(Data data) { - StringBuilder buffer = new StringBuilder(3001); - for (int i = 0; i < 3000; i++) { - buffer.append('a'); - } - data.string = buffer.toString(); - - data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"}; - data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.shorts = new short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float) Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; - - data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; - data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - - data.booleans = new boolean[] {true, false}; - data.Ints = new Integer[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.Shorts = new Short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.Floats = new Float[] {0f, -0f, 1f, -1f, 123456f, -123456f, 0.1f, 0.2f, -0.3f, (float) Math.PI, Float.MAX_VALUE, - Float.MIN_VALUE}; - data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.Longs = new Long[] {0l, -0l, 1l, -1l, 123456l, -123456l, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; - data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - data.Booleans = new Boolean[] {true, false}; - } - - private static - void register(SerializationManager manager) { - manager.register(int[].class); - manager.register(short[].class); - manager.register(float[].class); - manager.register(double[].class); - manager.register(long[].class); - manager.register(byte[].class); - manager.register(char[].class); - manager.register(boolean[].class); - manager.register(String[].class); - manager.register(Integer[].class); - manager.register(Short[].class); - manager.register(Float[].class); - manager.register(Double[].class); - manager.register(Long[].class); - manager.register(Byte[].class); - manager.register(Character[].class); - manager.register(Boolean[].class); - manager.register(Data.class); - manager.register(TYPE.class); - } - - public static - class Data { - public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public double[] doubles; - public long[] longs; - public byte[] bytes; - public char[] chars; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Double[] Doubles; - public Long[] Longs; - public Byte[] Bytes; - public Character[] Chars; - public Boolean[] Booleans; - - - @Override - public - int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(this.Booleans); - result = prime * result + Arrays.hashCode(this.Bytes); - result = prime * result + Arrays.hashCode(this.Chars); - result = prime * result + Arrays.hashCode(this.Doubles); - result = prime * result + Arrays.hashCode(this.Floats); - result = prime * result + Arrays.hashCode(this.Ints); - result = prime * result + Arrays.hashCode(this.Longs); - result = prime * result + Arrays.hashCode(this.Shorts); - result = prime * result + Arrays.hashCode(this.booleans); - result = prime * result + Arrays.hashCode(this.bytes); - result = prime * result + Arrays.hashCode(this.chars); - result = prime * result + Arrays.hashCode(this.doubles); - result = prime * result + Arrays.hashCode(this.floats); - result = prime * result + Arrays.hashCode(this.ints); - result = prime * result + Arrays.hashCode(this.longs); - result = prime * result + Arrays.hashCode(this.shorts); - result = prime * result + (this.string == null ? 0 : this.string.hashCode()); - result = prime * result + Arrays.hashCode(this.strings); - return result; - } - - @Override - public - boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Data other = (Data) obj; - if (!Arrays.equals(this.Booleans, other.Booleans)) { - return false; - } - if (!Arrays.equals(this.Bytes, other.Bytes)) { - return false; - } - if (!Arrays.equals(this.Chars, other.Chars)) { - return false; - } - if (!Arrays.equals(this.Doubles, other.Doubles)) { - return false; - } - if (!Arrays.equals(this.Floats, other.Floats)) { - return false; - } - if (!Arrays.equals(this.Ints, other.Ints)) { - return false; - } - if (!Arrays.equals(this.Longs, other.Longs)) { - return false; - } - if (!Arrays.equals(this.Shorts, other.Shorts)) { - return false; - } - if (!Arrays.equals(this.booleans, other.booleans)) { - return false; - } - if (!Arrays.equals(this.bytes, other.bytes)) { - return false; - } - if (!Arrays.equals(this.chars, other.chars)) { - return false; - } - if (!Arrays.equals(this.doubles, other.doubles)) { - return false; - } - if (!Arrays.equals(this.floats, other.floats)) { - return false; - } - if (!Arrays.equals(this.ints, other.ints)) { - return false; - } - if (!Arrays.equals(this.longs, other.longs)) { - return false; - } - if (!Arrays.equals(this.shorts, other.shorts)) { - return false; - } - if (this.string == null) { - if (other.string != null) { - return false; - } - } - else if (!this.string.equals(other.string)) { - return false; - } - if (!Arrays.equals(this.strings, other.strings)) { - return false; - } - return true; - } - - @Override - public - String toString() { - return "Data"; - } - } -} diff --git a/test/dorkbox/network/not-fixed/LargeResizeBufferTest.java b/test/dorkbox/network/not-fixed/LargeResizeBufferTest.java deleted file mode 100644 index 7afaa017..00000000 --- a/test/dorkbox/network/not-fixed/LargeResizeBufferTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.security.SecureRandom; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -public -class LargeResizeBufferTest extends BaseTest { - private static final int OBJ_SIZE = 1024 * 100; - - private volatile int finalCheckAmount = 0; - private volatile int serverCheck = -1; - private volatile int clientCheck = -1; - - @Test - public - void manyLargeMessages() throws SecurityException, IOException { - final int messageCount = 1024; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - server.listeners() - .add(new Listener.OnMessageReceived() { - AtomicInteger received = new AtomicInteger(); - AtomicInteger receivedBytes = new AtomicInteger(); - - @Override - public - void received(Connection connection, LargeMessage object) { - // System.err.println("Server ack message: " + received.get()); - - connection.send() - .TCP(object); - this.receivedBytes.addAndGet(object.bytes.length); - - if (this.received.incrementAndGet() == messageCount) { - System.out.println("Server received all " + messageCount + " messages!"); - System.out.println("Server received and sent " + this.receivedBytes.get() + " bytes."); - LargeResizeBufferTest.this.serverCheck = LargeResizeBufferTest.this.finalCheckAmount - this.receivedBytes.get(); - System.out.println("Server missed " + LargeResizeBufferTest.this.serverCheck + " bytes."); - stopEndPoints(); - } - } - }); - - Client client = new Client(configuration); - addEndPoint(client); - - client.listeners() - .add(new Listener.OnMessageReceived() { - AtomicInteger received = new AtomicInteger(); - AtomicInteger receivedBytes = new AtomicInteger(); - - @Override - public - void received(Connection connection, LargeMessage object) { - this.receivedBytes.addAndGet(object.bytes.length); - - int count = this.received.getAndIncrement(); - // System.out.println("Client received message: " + count); - - if (count == messageCount) { - System.out.println("Client received all " + messageCount + " messages!"); - System.out.println("Client received and sent " + this.receivedBytes.get() + " bytes."); - LargeResizeBufferTest.this.clientCheck = LargeResizeBufferTest.this.finalCheckAmount - this.receivedBytes.get(); - System.out.println("Client missed " + LargeResizeBufferTest.this.clientCheck + " bytes."); - } - } - }); - client.connect(5000); - - SecureRandom random = new SecureRandom(); - - System.err.println(" Client sending " + messageCount + " messages"); - for (int i = 0; i < messageCount; i++) { - this.finalCheckAmount += OBJ_SIZE; // keep increasing size - - byte[] b = new byte[OBJ_SIZE]; - random.nextBytes(b); - - // set some of the bytes to be all `244`, just so some compression can occur (to test that as well) - for (int j = 0; j < 400; j++) { - b[j] = (byte) 244; - } - -// System.err.println("Sending " + b.length + " bytes"); - client.send() - .TCP(new LargeMessage(b)); - } - - System.err.println("Client has queued " + messageCount + " messages."); - - waitForThreads(); - - if (this.clientCheck > 0) { - fail("Client missed " + this.clientCheck + " bytes."); - } - - if (this.serverCheck > 0) { - fail("Server missed " + this.serverCheck + " bytes."); - } - } - - private - void register(SerializationManager manager) { - manager.register(byte[].class); - manager.register(LargeMessage.class); - } - - public static - class LargeMessage { - public byte[] bytes; - - public - LargeMessage() { - } - - public - LargeMessage(byte[] bytes) { - this.bytes = bytes; - } - } -} diff --git a/test/dorkbox/network/not-fixed/MultipleThreadTest.java b/test/dorkbox/network/not-fixed/MultipleThreadTest.java deleted file mode 100644 index 34647d9a..00000000 --- a/test/dorkbox/network/not-fixed/MultipleThreadTest.java +++ /dev/null @@ -1,243 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.Listeners; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -public -class MultipleThreadTest extends BaseTest { - private final Object lock = new Object(); - private volatile boolean stillRunning = false; - - private final Object finalRunLock = new Object(); - private volatile boolean finalStillRunning = false; - - private final int messageCount = 150; - private final int threadCount = 15; - private final int clientCount = 13; - - private final List clients = new ArrayList(this.clientCount); - - int perClientReceiveTotal = (this.messageCount * this.threadCount); - int serverReceiveTotal = perClientReceiveTotal * this.clientCount; - - AtomicInteger sent = new AtomicInteger(0); - AtomicInteger totalClientReceived = new AtomicInteger(0); - AtomicInteger receivedServer = new AtomicInteger(1); - - ConcurrentHashMap sentStringsToClientDebug = new ConcurrentHashMap(); - - @Test - public - void multipleThreads() throws SecurityException, IOException { - // our clients should receive messageCount * threadCount * clientCount TOTAL messages - final int totalClientReceivedCountExpected = this.clientCount * this.messageCount * this.threadCount; - final int totalServerReceivedCountExpected = this.clientCount * this.messageCount; - - System.err.println("CLIENT RECEIVES: " + totalClientReceivedCountExpected); - System.err.println("SERVER RECEIVES: " + totalServerReceivedCountExpected); - - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(); - configuration.serialization.register(String[].class); - configuration.serialization.register(DataClass.class); - - - final Server server = new Server(configuration); - server.disableRemoteKeyValidation(); - - addEndPoint(server); - server.bind(false); - - - final Listeners listeners = server.listeners(); - listeners.add(new Listener.OnConnected() { - - @Override - public - void connected(final Connection connection) { - System.err.println("Client connected to server."); - - // kickoff however many threads we need, and send data to the client. - for (int i = 1; i <= MultipleThreadTest.this.threadCount; i++) { - final int index = i; - new Thread() { - @Override - public - void run() { - for (int i = 1; i <= MultipleThreadTest.this.messageCount; i++) { - int incrementAndGet = MultipleThreadTest.this.sent.getAndIncrement(); - DataClass dataClass = new DataClass("Server -> client. Thread #" + index + " message# " + incrementAndGet, - incrementAndGet); - - //System.err.println(dataClass.data); - MultipleThreadTest.this.sentStringsToClientDebug.put(incrementAndGet, dataClass); - connection.send() - .TCP(dataClass) - .flush(); - } - - } - }.start(); - } - } - }); - - listeners.add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, DataClass object) { - int incrementAndGet = MultipleThreadTest.this.receivedServer.getAndIncrement(); - //System.err.println("server #" + incrementAndGet); - - - if (incrementAndGet % MultipleThreadTest.this.messageCount == 0) { - System.err.println("Server receive DONE for client " + incrementAndGet); - - stillRunning = false; - synchronized (MultipleThreadTest.this.lock) { - MultipleThreadTest.this.lock.notifyAll(); - } - } - - if (incrementAndGet == totalServerReceivedCountExpected) { - System.err.println("Server DONE: " + incrementAndGet); - - finalStillRunning = false; - synchronized (MultipleThreadTest.this.finalRunLock) { - MultipleThreadTest.this.finalRunLock.notifyAll(); - } - } - } - }); - - // ---- - finalStillRunning = true; - for (int i = 1; i <= this.clientCount; i++) { - final int index = i; - - Client client = new Client(configuration); - this.clients.add(client); - - addEndPoint(client); - client.listeners() - .add(new Listener.OnMessageReceived() { - final int clientIndex = index; - final AtomicInteger received = new AtomicInteger(1); - - @Override - public - void received(Connection connection, DataClass object) { - totalClientReceived.getAndIncrement(); - int clientLocalCounter = this.received.getAndIncrement(); - MultipleThreadTest.this.sentStringsToClientDebug.remove(object.index); - - //System.err.println(object.data); - // we finished!! - if (clientLocalCounter == perClientReceiveTotal) { - //System.err.println("Client #" + clientIndex + " received " + clientLocalCounter + " Sending back " + - // MultipleThreadTest.this.messageCount + " messages."); - - // now spam back messages! - for (int i = 0; i < MultipleThreadTest.this.messageCount; i++) { - connection.send() - .TCP(new DataClass("Client #" + clientIndex + " -> Server message " + i, index)); - } - } - } - }); - - - stillRunning = true; - - client.connect(5000); - - while (stillRunning) { - synchronized (this.lock) { - try { - this.lock.wait(5 * 1000); // 5 secs - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - while (finalStillRunning) { - synchronized (this.finalRunLock) { - try { - this.finalRunLock.wait(5 * 1000); // 5 secs - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - // CLIENT will wait until it's done connecting, but SERVER is async. - // the ONLY way to safely work in the server is with LISTENERS. Everything else can FAIL, because of it's async nature. - - if (!this.sentStringsToClientDebug.isEmpty()) { - System.err.println("MISSED DATA: " + this.sentStringsToClientDebug.size()); - for (Map.Entry i : this.sentStringsToClientDebug.entrySet()) { - System.err.println(i.getKey() + " : " + i.getValue().data); - } - } - - stopEndPoints(); - assertEquals(totalClientReceivedCountExpected, totalClientReceived.get()); - - // offset by 1 since we start at 1 - assertEquals(totalServerReceivedCountExpected, receivedServer.get()-1); - } - - - public static - class DataClass { - public String data; - public Integer index; - - public - DataClass() { - } - - public - DataClass(String data, Integer index) { - this.data = data; - this.index = index; - } - } -} diff --git a/test/dorkbox/network/not-fixed/PingPongLocalTest.java b/test/dorkbox/network/not-fixed/PingPongLocalTest.java deleted file mode 100644 index 346d0eb8..00000000 --- a/test/dorkbox/network/not-fixed/PingPongLocalTest.java +++ /dev/null @@ -1,327 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.Listeners; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; -import dorkbox.util.serialization.SerializationManager; - -public -class PingPongLocalTest extends BaseTest { - int tries = 10000; - private volatile String fail; - - @Test - public void pingPongLocal() throws SecurityException, IOException { - this.fail = "Data not received."; - - final Data dataLOCAL = new Data(); - populateData(dataLOCAL); - - Configuration configuration = Configuration.localOnly(); - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - final Listeners listeners = server.listeners(); - listeners.add(new Listener.OnError() { - @Override - public - void error(Connection connection, Throwable throwable) { - PingPongLocalTest.this.fail = "Error during processing. " + throwable; - } - }); - listeners.add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, Data data) { - connection.id(); - if (!data.equals(dataLOCAL)) { - PingPongLocalTest.this.fail = "data is not equal on server."; - throw new RuntimeException("Fail! " + PingPongLocalTest.this.fail); - } - connection.send() - .TCP(data); - } - }); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - final Listeners listeners1 = client.listeners(); - listeners1.add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - PingPongLocalTest.this.fail = null; - connection.send() - .TCP(dataLOCAL); - // connection.sendUDP(dataUDP); // TCP and UDP are the same for a local channel. - } - }); - - listeners1.add(new Listener.OnError() { - @Override - public - void error(Connection connection, Throwable throwable) { - PingPongLocalTest.this.fail = "Error during processing. " + throwable; - System.err.println(PingPongLocalTest.this.fail); - } - }); - - listeners1.add(new Listener.OnMessageReceived() { - AtomicInteger check = new AtomicInteger(0); - - @Override - public - void received(Connection connection, Data data) { - if (!data.equals(dataLOCAL)) { - PingPongLocalTest.this.fail = "data is not equal on client."; - throw new RuntimeException("Fail! " + PingPongLocalTest.this.fail); - } - - if (this.check.getAndIncrement() <= PingPongLocalTest.this.tries) { - connection.send() - .TCP(data); - } - else { - System.err.println("Ran LOCAL " + PingPongLocalTest.this.tries + " times"); - stopEndPoints(); - } - } - }); - - client.connect(5000); - - waitForThreads(); - - if (this.fail != null) { - fail(this.fail); - } - } - - private void populateData(Data data) { - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < 3000; i++) { - buffer.append('a'); - } - data.string = buffer.toString(); - - data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789","",null,"!@#$","�����"}; - data.ints = new int[] {-1234567,1234567,-1,0,1,Integer.MAX_VALUE,Integer.MIN_VALUE}; - data.shorts = new short[] {-12345,12345,-1,0,1,Short.MAX_VALUE,Short.MIN_VALUE}; - data.floats = new float[] {0,-0,1,-1,123456,-123456,0.1f,0.2f,-0.3f,(float) Math.PI,Float.MAX_VALUE, - Float.MIN_VALUE}; - - data.doubles = new double[] {0,-0,1,-1,123456,-123456,0.1d,0.2d,-0.3d,Math.PI,Double.MAX_VALUE,Double.MIN_VALUE}; - data.longs = new long[] {0,-0,1,-1,123456,-123456,99999999999l,-99999999999l,Long.MAX_VALUE,Long.MIN_VALUE}; - data.bytes = new byte[] {-123,123,-1,0,1,Byte.MAX_VALUE,Byte.MIN_VALUE}; - data.chars = new char[] {32345,12345,0,1,63,Character.MAX_VALUE,Character.MIN_VALUE}; - - data.booleans = new boolean[] {true,false}; - data.Ints = new Integer[] {-1234567,1234567,-1,0,1,Integer.MAX_VALUE,Integer.MIN_VALUE}; - data.Shorts = new Short[] {-12345,12345,-1,0,1,Short.MAX_VALUE,Short.MIN_VALUE}; - data.Floats = new Float[] {0f,-0f,1f,-1f,123456f,-123456f,0.1f,0.2f,-0.3f,(float) Math.PI,Float.MAX_VALUE, - Float.MIN_VALUE}; - data.Doubles = new Double[] {0d,-0d,1d,-1d,123456d,-123456d,0.1d,0.2d,-0.3d,Math.PI,Double.MAX_VALUE, - Double.MIN_VALUE}; - data.Longs = new Long[] {0l,-0l,1l,-1l,123456l,-123456l,99999999999l,-99999999999l,Long.MAX_VALUE, - Long.MIN_VALUE}; - data.Bytes = new Byte[] {-123,123,-1,0,1,Byte.MAX_VALUE,Byte.MIN_VALUE}; - data.Chars = new Character[] {32345,12345,0,1,63,Character.MAX_VALUE,Character.MIN_VALUE}; - data.Booleans = new Boolean[] {true,false}; - } - - private void register(SerializationManager manager) { - manager.register(int[].class); - manager.register(short[].class); - manager.register(float[].class); - manager.register(double[].class); - manager.register(long[].class); - manager.register(byte[].class); - manager.register(char[].class); - manager.register(boolean[].class); - manager.register(String[].class); - manager.register(Integer[].class); - manager.register(Short[].class); - manager.register(Float[].class); - manager.register(Double[].class); - manager.register(Long[].class); - manager.register(Byte[].class); - manager.register(Character[].class); - manager.register(Boolean[].class); - manager.register(Data.class); - } - - static public class Data { - public String string; - - public String[] strings; - - public int[] ints; - - public short[] shorts; - - public float[] floats; - - public double[] doubles; - - public long[] longs; - - public byte[] bytes; - - public char[] chars; - - public boolean[] booleans; - - public Integer[] Ints; - - public Short[] Shorts; - - public Float[] Floats; - - public Double[] Doubles; - - public Long[] Longs; - - public Byte[] Bytes; - - public Character[] Chars; - - public Boolean[] Booleans; - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(this.Booleans); - result = prime * result + Arrays.hashCode(this.Bytes); - result = prime * result + Arrays.hashCode(this.Chars); - result = prime * result + Arrays.hashCode(this.Doubles); - result = prime * result + Arrays.hashCode(this.Floats); - result = prime * result + Arrays.hashCode(this.Ints); - result = prime * result + Arrays.hashCode(this.Longs); - result = prime * result + Arrays.hashCode(this.Shorts); - result = prime * result + Arrays.hashCode(this.booleans); - result = prime * result + Arrays.hashCode(this.bytes); - result = prime * result + Arrays.hashCode(this.chars); - result = prime * result + Arrays.hashCode(this.doubles); - result = prime * result + Arrays.hashCode(this.floats); - result = prime * result + Arrays.hashCode(this.ints); - result = prime * result + Arrays.hashCode(this.longs); - result = prime * result + Arrays.hashCode(this.shorts); - result = prime * result + (this.string == null ? 0 : this.string.hashCode()); - result = prime * result + Arrays.hashCode(this.strings); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Data other = (Data) obj; - if (!Arrays.equals(this.Booleans, other.Booleans)) { - return false; - } - if (!Arrays.equals(this.Bytes, other.Bytes)) { - return false; - } - if (!Arrays.equals(this.Chars, other.Chars)) { - return false; - } - if (!Arrays.equals(this.Doubles, other.Doubles)) { - return false; - } - if (!Arrays.equals(this.Floats, other.Floats)) { - return false; - } - if (!Arrays.equals(this.Ints, other.Ints)) { - return false; - } - if (!Arrays.equals(this.Longs, other.Longs)) { - return false; - } - if (!Arrays.equals(this.Shorts, other.Shorts)) { - return false; - } - if (!Arrays.equals(this.booleans, other.booleans)) { - return false; - } - if (!Arrays.equals(this.bytes, other.bytes)) { - return false; - } - if (!Arrays.equals(this.chars, other.chars)) { - return false; - } - if (!Arrays.equals(this.doubles, other.doubles)) { - return false; - } - if (!Arrays.equals(this.floats, other.floats)) { - return false; - } - if (!Arrays.equals(this.ints, other.ints)) { - return false; - } - if (!Arrays.equals(this.longs, other.longs)) { - return false; - } - if (!Arrays.equals(this.shorts, other.shorts)) { - return false; - } - if (this.string == null) { - if (other.string != null) { - return false; - } - } else if (!this.string.equals(other.string)) { - return false; - } - if (!Arrays.equals(this.strings, other.strings)) { - return false; - } - return true; - } - - @Override - public String toString() { - return "Data"; - } - } -} diff --git a/test/dorkbox/network/not-fixed/PingTest.java b/test/dorkbox/network/not-fixed/PingTest.java deleted file mode 100644 index 965ed5b2..00000000 --- a/test/dorkbox/network/not-fixed/PingTest.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright 2010 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Ping; -import dorkbox.network.connection.PingListener; -import dorkbox.util.exceptions.SecurityException; - -public -class PingTest extends BaseTest { - - private volatile int response = -1; - - @Test - public - void pingLocal() throws SecurityException, IOException { - this.response = -1; - - Server server = new Server(); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing LOCAL ping"); - for (int i = 0; i < 10; i++) { - this.response = client.send() - .ping() - .getResponse(); - System.err.println("Ping: " + this.response); - } - - stopEndPoints(); - if (this.response == -1) { - fail(); - } - } - - // ping prefers the following order: UDP, TCP - @Test - public - void pingTCP() throws SecurityException, IOException { - this.response = -1; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing TCP ping"); - for (int i = 0; i < 10; i++) { - this.response = client.send() - .ping() - .getResponse(); - System.err.println("Ping: " + this.response); - } - - stopEndPoints(); - if (this.response == -1) { - fail(); - } - } - - @Test - public - void pingLocal_testListeners1() throws SecurityException, IOException { - this.response = -1; - - Server server = new Server(); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing LOCAL ping with multi callback"); - - final PingListener pingListener = new PingListener() { - AtomicInteger count = new AtomicInteger(); - - @Override - public - void response(Connection connection, int pingResponseTime) { - System.err.println("Ping: " + pingResponseTime); - - if (this.count.incrementAndGet() < 10) { - connection.send() - .ping() - .add(this); - } - else { - PingTest.this.response = pingResponseTime; - stopEndPoints(); - } - } - }; - - // alternate way to register for the receipt of a one-off ping response - // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten - Ping ping = client.send() - .ping(); - ping.add(pingListener); - - waitForThreads(); - - if (this.response == -1) { - fail(); - } - } - - @Test - public - void pingTCP_testListeners1() throws SecurityException, IOException { - this.response = -1; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing TCP ping with multi callback"); - - final PingListener pingListener = new PingListener() { - AtomicInteger count = new AtomicInteger(); - - @Override - public - void response(Connection connection, int pingResponseTime) { - System.err.println("Ping: " + pingResponseTime); - - if (this.count.incrementAndGet() < 10) { - connection.send() - .ping() - .add(this); - } - else { - PingTest.this.response = pingResponseTime; - stopEndPoints(); - } - } - }; - - // alternate way to register for the receipt of a one-off ping response - // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten - Ping ping = client.send() - .ping(); - ping.add(pingListener); - - waitForThreads(); - - if (this.response == -1) { - fail(); - } - } - - @Test - public - void pingLocal_testListeners2() throws SecurityException, IOException { - this.response = -1; - - Server server = new Server(); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing TCP ping with single callback"); - - final PingListener pingListener = new PingListener() { - @Override - public - void response(Connection connection, int pingResponseTime) { - System.err.println("Ping: " + pingResponseTime); - PingTest.this.response = pingResponseTime; - stopEndPoints(); - } - }; - - - // alternate way to register for the receipt of a one-off ping response - // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten - Ping ping = client.send() - .ping(); - ping.add(pingListener); - - waitForThreads(); - if (this.response == -1) { - fail(); - } - } - - @Test - public - void pingTCP_testListeners2() throws SecurityException, IOException { - this.response = -1; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing TCP ping with single callback"); - - final PingListener pingListener = new PingListener() { - @Override - public - void response(Connection connection, int pingResponseTime) { - System.err.println("Ping: " + pingResponseTime); - PingTest.this.response = pingResponseTime; - stopEndPoints(); - } - }; - - - // alternate way to register for the receipt of a one-off ping response - // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten - Ping ping = client.send() - .ping(); - ping.add(pingListener); - - waitForThreads(); - if (this.response == -1) { - fail(); - } - } - - // ping prefers the following order: UDP, TCP - @Test - public - void pingUDP() throws SecurityException, IOException { - this.response = -1; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - - client.connect(5000); - - System.err.println("Testing UDP ping"); - for (int i = 0; i < 10; i++) { - this.response = client.send() - .ping() - .getResponse(); - System.err.println("Ping: " + this.response); - } - - stopEndPoints(); - - if (this.response == -1) { - fail(); - } - } -} diff --git a/test/dorkbox/network/not-fixed/ReconnectTest.java b/test/dorkbox/network/not-fixed/ReconnectTest.java deleted file mode 100644 index b8b90876..00000000 --- a/test/dorkbox/network/not-fixed/ReconnectTest.java +++ /dev/null @@ -1,296 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.Listeners; -import dorkbox.util.exceptions.SecurityException; - -// NOTE: UDP is unreliable, EVEN ON LOOPBACK! So this can fail with UDP. TCP will never fail. -public -class ReconnectTest extends BaseTest { - private final AtomicInteger receivedCount = new AtomicInteger(0); - - private static final Logger logger = LoggerFactory.getLogger(ReconnectTest.class.getSimpleName()); - - @Test - public - void socketReuseUDP() throws IOException, SecurityException { - socketReuse(false, true); - } - - @Test - public - void socketReuseTCP() throws IOException, SecurityException { - socketReuse(true, false); - } - - @Test - public - void socketReuseTCPUDP() throws IOException, SecurityException { - socketReuse(true, true); - } - - private - void socketReuse(final boolean useTCP, final boolean useUDP) throws SecurityException, IOException { - receivedCount.set(0); - - Configuration configuration = new Configuration(); - configuration.host = host; - - if (useTCP) { - configuration.tcpPort = tcpPort; - } - - if (useUDP) { - configuration.udpPort = udpPort; - } - - AtomicReference latch = new AtomicReference(); - - - Server server = new Server(configuration); - addEndPoint(server); - final Listeners listeners = server.listeners(); - listeners.add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - if (useTCP) { - connection.send() - .TCP("-- TCP from server"); - } - if (useUDP) { - connection.send() - .UDP("-- UDP from server"); - } - } - }); - listeners.add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, String object) { - int incrementAndGet = ReconnectTest.this.receivedCount.incrementAndGet(); - logger.error("----- " + incrementAndGet + " : " + object); - - latch.get().countDown(); - } - }); - server.bind(false); - - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - final Listeners listeners1 = client.listeners(); - listeners1.add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - if (useTCP) { - connection.send() - .TCP("-- TCP from client"); - } - if (useUDP) { - connection.send() - .UDP("-- UDP from client"); - } - } - }); - listeners1.add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, String object) { - int incrementAndGet = ReconnectTest.this.receivedCount.incrementAndGet(); - logger.error("----- " + incrementAndGet + " : " + object); - - latch.get().countDown(); - } - }); - - - - int latchCount = 2; - int count = 100; - int initialCount = 2; - if (useTCP && useUDP) { - initialCount += 2; - latchCount += 2; - } - - - try { - for (int i = 1; i < count + 1; i++) { - logger.error("....."); - latch.set(new CountDownLatch(latchCount)); - - try { - client.connect(5000); - } catch (IOException e) { - e.printStackTrace(); - } - - int retryCount = 20; - int lastRetryCount; - - int target = i * initialCount; - boolean failed = false; - - synchronized (receivedCount) { - while (this.receivedCount.get() != target) { - lastRetryCount = this.receivedCount.get(); - - try { - latch.get().await(1, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - // check to see if we changed at all... - if (lastRetryCount == this.receivedCount.get()) { - if (retryCount-- < 0) { - logger.error("Aborting unit test... wrong count!"); - if (useUDP) { - // If TCP and UDP both fill the pipe, THERE WILL BE FRAGMENTATION and dropped UDP packets! - // it results in severe UDP packet loss and contention. - // - // http://www.isoc.org/INET97/proceedings/F3/F3_1.HTM - // also, a google search on just "INET97/proceedings/F3/F3_1.HTM" turns up interesting problems. - // Usually it's with ISPs. - - logger.error("NOTE: UDP can fail, even on loopback! See: http://www.isoc.org/INET97/proceedings/F3/F3_1.HTM"); - } - failed = true; - break; - } - } else { - retryCount = 20; - } - } - } - - client.close(); - logger.error("....."); - - if (failed) { - break; - } - } - - int specified = count * initialCount; - int received = this.receivedCount.get(); - - if (specified != received) { - logger.error("NOTE: UDP can fail, even on loopback! See: http://www.isoc.org/INET97/proceedings/F3/F3_1.HTM"); - } - - assertEquals(specified, received); - } finally { - stopEndPoints(); - waitForThreads(10); - } - } - - @Test - public - void localReuse() throws SecurityException, IOException { - receivedCount.set(0); - - Server server = new Server(); - addEndPoint(server); - server.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - connection.send() - .self("-- LOCAL from server"); - } - }); - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, String object) { - int incrementAndGet = ReconnectTest.this.receivedCount.incrementAndGet(); - System.out.println("----- " + incrementAndGet + " : " + object); - } - }); - - // ---- - - Client client = new Client(); - addEndPoint(client); - client.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - connection.send() - .self("-- LOCAL from client"); - } - }); - - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, String object) { - int incrementAndGet = ReconnectTest.this.receivedCount.incrementAndGet(); - System.out.println("----- " + incrementAndGet + " : " + object); - } - }); - - server.bind(false); - int count = 10; - for (int i = 1; i < count + 1; i++) { - client.connect(5000); - - int target = i * 2; - while (this.receivedCount.get() != target) { - System.out.println("----- Waiting..."); - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { - } - } - - client.close(); - } - - assertEquals(count * 2, this.receivedCount.get()); - - stopEndPoints(); - waitForThreads(10); - } -} diff --git a/test/dorkbox/network/not-fixed/SocketOpenTest.java b/test/dorkbox/network/not-fixed/SocketOpenTest.java deleted file mode 100644 index 484f218f..00000000 --- a/test/dorkbox/network/not-fixed/SocketOpenTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2018 dorkbox, llc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; -import java.net.Socket; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.junit.Assert; -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener.OnConnected; -import dorkbox.util.exceptions.SecurityException; - -/** - * - */ -public -class SocketOpenTest extends BaseTest { - CountDownLatch latch = new CountDownLatch(1); - - @Test - public - void socketConnect() throws SecurityException { - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.host = host; - - Server server = new Server(configuration); - addEndPoint(server); - - server.listeners() - .add(new OnConnected() { - @Override - public - void connected(final Connection connection) { - latch.countDown(); - } - }); - - - server.bind(false); - - boolean connectedSocket = false; - - // since we check the socket, if we are NOT connected to a socket, then we're done. - Socket sock = null; - try { - sock = new Socket(host, tcpPort); - if (sock.isConnected()) { - // connected to server - connectedSocket = true; - sock.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (sock != null) { - sock.close(); - } - } catch (IOException ignored) { - } - } - - - Assert.assertTrue(connectedSocket); - - - Client client = new Client(configuration); - addEndPoint(client); - - try { - client.connect(5000); - } catch (IOException e) { - e.printStackTrace(); - } - - - try { - latch.await(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Assert.fail("Interrupted while waiting for latch..."); - } - - - stopEndPoints(); - waitForThreads(10); - } -} diff --git a/test/dorkbox/network/not-fixed/UnregisteredClassTest.java b/test/dorkbox/network/not-fixed/UnregisteredClassTest.java deleted file mode 100644 index 77dd010c..00000000 --- a/test/dorkbox/network/not-fixed/UnregisteredClassTest.java +++ /dev/null @@ -1,346 +0,0 @@ -/* Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.Listeners; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -public -class UnregisteredClassTest extends BaseTest { - private String fail; - private int tries = 10000; - - private AtomicInteger receivedTCP = new AtomicInteger(); - private AtomicInteger receivedUDP = new AtomicInteger(); - - @Test - public - void unregisteredClasses() throws SecurityException, IOException { - int origSize = EndPoint.udpMaxSize; - EndPoint.udpMaxSize = 2048; - - Configuration configuration = new Configuration(); - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - configuration.serialization = Serialization.DEFAULT(false, false, null); - - - System.err.println("Running test " + this.tries + " times, please wait for it to finish."); - - final Data dataTCP = new Data(); - populateData(dataTCP, true); - final Data dataUDP = new Data(); - populateData(dataUDP, false); - - Server server = new Server(configuration); - addEndPoint(server); - server.bind(false); - server.listeners() - .add(new Listener.OnError() { - @Override - public - void error(Connection connection, Throwable throwable) { - UnregisteredClassTest.this.fail = "Error during processing. " + throwable; - } - }); - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, Data data) { - if (data.isTCP) { - if (!data.equals(dataTCP)) { - UnregisteredClassTest.this.fail = "TCP data is not equal on server."; - throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail); - } - connection.send() - .TCP(data); - UnregisteredClassTest.this.receivedTCP.incrementAndGet(); - } - else { - if (!data.equals(dataUDP)) { - UnregisteredClassTest.this.fail = "UDP data is not equal on server."; - throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail); - } - connection.send() - .UDP(data); - UnregisteredClassTest.this.receivedUDP.incrementAndGet(); - } - } - }); - - // ---- - - Client client = new Client(configuration); - addEndPoint(client); - final Listeners listeners = client.listeners(); - listeners.add(new Listener.OnConnected() { - @Override - public - void connected(Connection connection) { - UnregisteredClassTest.this.fail = null; - connection.send() - .TCP(dataTCP); - connection.send() - .UDP(dataUDP); // UDP ping pong stops if a UDP packet is lost. - } - }); - listeners.add(new Listener.OnError() { - @Override - public - void error(Connection connection, Throwable throwable) { - UnregisteredClassTest.this.fail = "Error during processing. " + throwable; - System.err.println(UnregisteredClassTest.this.fail); - } - }); - listeners.add(new Listener.OnMessageReceived() { - AtomicInteger checkTCP = new AtomicInteger(0); - AtomicInteger checkUDP = new AtomicInteger(0); - AtomicBoolean doneTCP = new AtomicBoolean(false); - AtomicBoolean doneUDP = new AtomicBoolean(false); - - @Override - public - void received(Connection connection, Data data) { - if (data.isTCP) { - if (!data.equals(dataTCP)) { - UnregisteredClassTest.this.fail = "TCP data is not equal on client."; - throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail); - } - if (this.checkTCP.getAndIncrement() <= UnregisteredClassTest.this.tries) { - connection.send() - .TCP(data); - UnregisteredClassTest.this.receivedTCP.incrementAndGet(); - } - else { - System.err.println("TCP done."); - this.doneTCP.set(true); - } - } - else { - if (!data.equals(dataUDP)) { - UnregisteredClassTest.this.fail = "UDP data is not equal on client."; - throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail); - } - if (this.checkUDP.getAndIncrement() <= UnregisteredClassTest.this.tries) { - connection.send() - .UDP(data); - UnregisteredClassTest.this.receivedUDP.incrementAndGet(); - } - else { - System.err.println("UDP done."); - this.doneUDP.set(true); - } - } - - if (this.doneTCP.get() && this.doneUDP.get()) { - System.err.println("Ran TCP & UDP " + UnregisteredClassTest.this.tries + " times each"); - stopEndPoints(); - } - } - }); - - client.connect(5000); - waitForThreads(); - - if (this.fail != null) { - fail(this.fail); - } - - EndPoint.udpMaxSize = origSize; - } - - private - void populateData(Data data, boolean isTCP) { - data.isTCP = isTCP; - - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < 3; i++) { - buffer.append('a'); - } - data.string = buffer.toString(); - - data.strings = new String[] {"ab012", "", null, "!@#$", "�����"}; - data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.shorts = new short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float) Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; - data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; - data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - data.booleans = new boolean[] {true, false}; - data.Ints = new Integer[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; - data.Shorts = new Short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE}; - data.Floats = new Float[] {0f, -0f, 1f, -1f, 123456f, -123456f, 0.1f, 0.2f, -0.3f, (float) Math.PI, Float.MAX_VALUE, - Float.MIN_VALUE}; - data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.Longs = new Long[] {0l, -0l, 1l, -1l, 123456l, -123456l, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; - data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; - data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; - data.Booleans = new Boolean[] {true, false}; - } - - static public - class Data { - public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public double[] doubles; - public long[] longs; - public byte[] bytes; - public char[] chars; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Double[] Doubles; - public Long[] Longs; - public Byte[] Bytes; - public Character[] Chars; - public Boolean[] Booleans; - public boolean isTCP; - - @Override - public - int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(this.Booleans); - result = prime * result + Arrays.hashCode(this.Bytes); - result = prime * result + Arrays.hashCode(this.Chars); - result = prime * result + Arrays.hashCode(this.Doubles); - result = prime * result + Arrays.hashCode(this.Floats); - result = prime * result + Arrays.hashCode(this.Ints); - result = prime * result + Arrays.hashCode(this.Longs); - result = prime * result + Arrays.hashCode(this.Shorts); - result = prime * result + Arrays.hashCode(this.booleans); - result = prime * result + Arrays.hashCode(this.bytes); - result = prime * result + Arrays.hashCode(this.chars); - result = prime * result + Arrays.hashCode(this.doubles); - result = prime * result + Arrays.hashCode(this.floats); - result = prime * result + Arrays.hashCode(this.ints); - result = prime * result + (this.isTCP ? 1231 : 1237); - result = prime * result + Arrays.hashCode(this.longs); - result = prime * result + Arrays.hashCode(this.shorts); - result = prime * result + (this.string == null ? 0 : this.string.hashCode()); - result = prime * result + Arrays.hashCode(this.strings); - return result; - } - - @Override - public - boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Data other = (Data) obj; - if (!Arrays.equals(this.Booleans, other.Booleans)) { - return false; - } - if (!Arrays.equals(this.Bytes, other.Bytes)) { - return false; - } - if (!Arrays.equals(this.Chars, other.Chars)) { - return false; - } - if (!Arrays.equals(this.Doubles, other.Doubles)) { - return false; - } - if (!Arrays.equals(this.Floats, other.Floats)) { - return false; - } - if (!Arrays.equals(this.Ints, other.Ints)) { - return false; - } - if (!Arrays.equals(this.Longs, other.Longs)) { - return false; - } - if (!Arrays.equals(this.Shorts, other.Shorts)) { - return false; - } - if (!Arrays.equals(this.booleans, other.booleans)) { - return false; - } - if (!Arrays.equals(this.bytes, other.bytes)) { - return false; - } - if (!Arrays.equals(this.chars, other.chars)) { - return false; - } - if (!Arrays.equals(this.doubles, other.doubles)) { - return false; - } - if (!Arrays.equals(this.floats, other.floats)) { - return false; - } - if (!Arrays.equals(this.ints, other.ints)) { - return false; - } - if (this.isTCP != other.isTCP) { - return false; - } - if (!Arrays.equals(this.longs, other.longs)) { - return false; - } - if (!Arrays.equals(this.shorts, other.shorts)) { - return false; - } - if (this.string == null) { - if (other.string != null) { - return false; - } - } - else if (!this.string.equals(other.string)) { - return false; - } - if (!Arrays.equals(this.strings, other.strings)) { - return false; - } - return true; - } - - @Override - public - String toString() { - return "Data"; - } - } -} diff --git a/test/dorkbox/network/not-fixed/connection/PropertyStoreAccessTest.java b/test/dorkbox/network/not-fixed/connection/PropertyStoreAccessTest.java deleted file mode 100644 index 86ffa23e..00000000 --- a/test/dorkbox/network/not-fixed/connection/PropertyStoreAccessTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2011 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import static org.junit.Assert.fail; - -import org.junit.Test; - -import dorkbox.network.BaseTest; -import dorkbox.util.exceptions.SecurityException; - - -public -class PropertyStoreAccessTest extends BaseTest { - - @Test - public - void testAccess() throws SecurityException { - PropertyStore store = new PropertyStore(); - store.init(null, null); - - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println("security violations are expected"); - System.out.println(); - System.out.println(); - System.out.println(); - - try { - store.getPrivateKey(); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.savePrivateKey(null); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.getPublicKey(); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.savePublicKey(null); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.getRegisteredServerKey(null); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.addRegisteredServerKey(null, null); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - try { - store.removeRegisteredServerKey(null); // this should throw a security exception - fail("Failed to pass the security test"); - } catch (SecurityException ignored) { - } - - store.getSalt(); // should not throw any errors - store.close(); - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationSpamTest.java b/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationSpamTest.java deleted file mode 100644 index 96117be1..00000000 --- a/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationSpamTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2020 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import org.junit.Test; - -import dorkbox.network.BaseTest; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.Server; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.NetworkSerializationManager; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -@SuppressWarnings("Duplicates") -public -class RmiDelayedInvocationSpamTest extends BaseTest { - private final int totalRuns = 1_000_000; - private final AtomicLong counter = new AtomicLong(0); - - @Test - public - void rmiNetwork() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.tcpPort = tcpPort; - configuration.host = host; - } - }); - } - - @Test - public - void rmiLocal() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - } - }); - } - - void register(final NetworkSerializationManager serialization) { - serialization.registerRmi(TestObject.class, TestObjectImpl.class); - } - - /** - * In this test the server has two objects in an object space. The client - * uses the first remote object to get the second remote object. - */ - public - void rmi(final Config config) throws SecurityException, IOException { - Configuration configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Server server = new Server(configuration); - server.setIdleTimeout(0); - - - addEndPoint(server); - server.bind(false); - - final int testObjectInt = server.createGlobalObject(new TestObjectImpl(counter)); - - // ---- - configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Client client = new Client(configuration); - client.setIdleTimeout(0); - - addEndPoint(client); - client.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - connection.getRemoteObject(testObjectInt, new RemoteObjectCallback() { - @Override - public - void created(final TestObject remoteObject) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - @Override - public - void run() { - System.err.println("Running for " + totalRuns + " iterations...."); - - RemoteObject obj = (RemoteObject) remoteObject; - obj.setResponseTimeout(1000); - - for (long i = 0; i < totalRuns; i++) { - // sometimes, this method is never called right away. - if (i % (totalRuns/100) == 0) { - System.err.print('.'); - } - - try { - remoteObject.setOther(i); - } catch (Exception e) { - System.err.println("Timedout when calling RMI method"); - break; - } - } - - stopEndPoints(); - } - }.start(); - } - }); - } - }); - - client.connect(0); - - waitForThreads(); - assertEquals(totalRuns, counter.get()); - } - - private - interface TestObject { - boolean setOther(long value); - long other(); - } - - - private static final AtomicInteger idCounter = new AtomicInteger(); - - private static - class TestObjectImpl implements TestObject { - private final transient int ID = idCounter.getAndIncrement(); - - private final AtomicLong counter; - private long value; - - public - TestObjectImpl(final AtomicLong counter) { - this.counter = counter; - } - - @Override - public - boolean setOther(final long aFloat) { - this.value = aFloat; - counter.getAndIncrement(); - - return true; - } - - @Override - public - long other() { - return value; - } - - @Override - public - int hashCode() { - return ID; - } - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationTest.java b/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationTest.java deleted file mode 100644 index 9f70f972..00000000 --- a/test/dorkbox/network/not-fixed/rmi/RmiDelayedInvocationTest.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2016 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import dorkbox.network.BaseTest; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.Server; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.NetworkSerializationManager; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -@SuppressWarnings("Duplicates") -public -class RmiDelayedInvocationTest extends BaseTest { - - private final Object iterateLock = new Object(); - - @Test - public - void rmiNetwork() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.tcpPort = tcpPort; - configuration.host = host; - } - }); - } - - @Test - public - void rmiLocal() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - } - }); - } - - void register(final NetworkSerializationManager serialization) { - serialization.registerRmi(TestObject.class, TestObjectImpl.class); - } - - /** - * In this test the server has two objects in an object space. The client - * uses the first remote object to get the second remote object. - */ - public - void rmi(final Config config) throws SecurityException, IOException { - Configuration configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Server server = new Server(configuration); - server.setIdleTimeout(0); - - - addEndPoint(server); - server.bind(false); - - final int testObjectInt = server.createGlobalObject(new TestObjectImpl(iterateLock)); - - // ---- - configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Client client = new Client(configuration); - client.setIdleTimeout(0); - - addEndPoint(client); - client.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - connection.getRemoteObject(testObjectInt, new RemoteObjectCallback() { - @Override - public - void created(final TestObject remoteObject) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - int totalRuns = 100_000; - @Override - public - void run() { - System.err.println("Running for " + totalRuns + " iterations...."); - - for (int i = 0; i < totalRuns; i++) { - if (i % 10000 == 0) { - System.err.println(i); - } - // sometimes, this method is never called right away. - remoteObject.setOther(i); - - synchronized (iterateLock) { - try { - iterateLock.wait(1000); - } catch (InterruptedException e) { - System.err.println("Failed after: " + i); - e.printStackTrace(); - break; - } - } - } - - System.err.println("Done with delay invocation test"); - stopEndPoints(); - } - }.start(); - } - }); - } - }); - - client.connect(0); - - waitForThreads(9999999); - } - - private - interface TestObject { - void setOther(float aFloat); - float other(); - } - - - private static final AtomicInteger idCounter = new AtomicInteger(); - - private static - class TestObjectImpl implements TestObject { - private final transient int ID = idCounter.getAndIncrement(); - - private float aFloat; - private Object iterateLock; - - public - TestObjectImpl(final Object iterateLock) { - this.iterateLock = iterateLock; - } - - @Override - public - void setOther(final float aFloat) { - this.aFloat = aFloat; - synchronized (iterateLock) { - iterateLock.notify(); - } - } - - @Override - public - float other() { - return aFloat; - } - - @Override - public - int hashCode() { - return ID; - } - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/RmiGlobalTest.java b/test/dorkbox/network/not-fixed/rmi/RmiGlobalTest.java deleted file mode 100644 index b5d514e6..00000000 --- a/test/dorkbox/network/not-fixed/rmi/RmiGlobalTest.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright 2016 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Test; - -import dorkbox.network.BaseTest; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.Server; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.ConnectionImpl; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.NetworkSerializationManager; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -public -class RmiGlobalTest extends BaseTest { - - private int CLIENT_GLOBAL_OBJECT_ID = 0; - private int SERVER_GLOBAL_OBJECT_ID = 0; - - private final TestCow globalRemoteServerObject = new TestCowImpl(); - private final TestCow globalRemoteClientObject = new TestCowImpl(); - - private static - void runTest(final Connection connection, final TestCow globalObject, final TestCow test, final int remoteObjectID) { - System.err.println("Starting test for: " + remoteObjectID); - - assertEquals(globalObject.hashCode(), test.hashCode()); - RemoteObject remoteObject = (RemoteObject) test; - - // Default behavior. RMI is transparent, method calls behave like normal - // (return values and exceptions are returned, call is synchronous) - System.err.println("hashCode: " + test.hashCode()); - System.err.println("toString: " + test); - - // see what the "remote" toString() method is - final String s = remoteObject.toString(); - remoteObject.enableToString(true); - assertFalse(s.equals(remoteObject.toString())); - - - test.moo(); - test.moo("Cow"); - assertEquals(remoteObjectID, test.id()); - - - // UDP calls that ignore the return value - remoteObject.setUDP(); - remoteObject.setAsync(true); - remoteObject.setTransmitReturnValue(false); - remoteObject.setTransmitExceptions(false); - test.moo("Meow"); - assertEquals(0, test.id()); - remoteObject.setAsync(false); - remoteObject.setTransmitReturnValue(true); - remoteObject.setTransmitExceptions(true); - remoteObject.setTCP(); - - - // Test that RMI correctly waits for the remotely invoked method to exit - remoteObject.setResponseTimeout(5000); - test.moo("You should see this two seconds before...", 2000); - System.out.println("...This"); - remoteObject.setResponseTimeout(3000); - - // Try exception handling - boolean caught = false; - try { - test.throwException(); - } catch (UnsupportedOperationException ex) { - System.err.println("\tExpected exception! " + ex.getMessage()); - caught = true; - } - assertTrue(caught); - - - // Return values are ignored, but exceptions are still dealt with properly - remoteObject.setTransmitReturnValue(false); - test.moo("Baa"); - test.id(); - caught = false; - try { - test.throwException(); - } catch (UnsupportedOperationException ex) { - caught = true; - } - assertTrue(caught); - - // Non-blocking call that ignores the return value - remoteObject.setAsync(true); - remoteObject.setTransmitReturnValue(false); - test.moo("Meow"); - assertEquals(0, test.id()); - - // Non-blocking call that returns the return value - remoteObject.setTransmitReturnValue(true); - test.moo("Foo"); - - assertEquals(0, test.id()); - - // wait for the response to id() - assertEquals(remoteObjectID, remoteObject.waitForLastResponse()); - - assertEquals(0, test.id()); - byte responseID = remoteObject.getLastResponseID(); - // wait for the response to id() - assertEquals(remoteObjectID, remoteObject.waitForResponse(responseID)); - - // Non-blocking call that errors out - remoteObject.setTransmitReturnValue(false); - test.throwException(); - assertEquals(remoteObject.waitForLastResponse() - .getClass(), UnsupportedOperationException.class); - - // Call will time out if non-blocking isn't working properly - remoteObject.setTransmitExceptions(false); - test.moo("Mooooooooo", 3000); - - - // should wait for a small time - remoteObject.setTransmitReturnValue(true); - remoteObject.setAsync(false); - remoteObject.setResponseTimeout(6000); - System.out.println("You should see this 2 seconds before"); - float slow = test.slow(); - System.out.println("...This"); - assertEquals(123.0F, slow, 0.0001D); - - - // Test sending a reference to a remote object (the receiving end should receive the IMPL object, not the proxy object) - System.out.println("Sending proxied object to remote..."); - MessageWithTestCow m = new MessageWithTestCow(test); - m.number = 678; - m.text = "sometext"; - - connection.send() - .TCP(m) - .flush(); - } - - - - public static - void register(NetworkSerializationManager manager) { - manager.register(Object.class); // Needed for Object#toString, hashCode, etc. - manager.register(MessageWithTestCow.class); - manager.register(UnsupportedOperationException.class); - } - - @Test - public - void rmiNetwork() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - } - }); - } - - @Test - public - void rmiLocal() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - } - }); - } - - public - void rmi(final Config config) throws SecurityException, IOException { - Configuration configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - // NOTICE: none of the super classes/interfaces are registered! - configuration.serialization.registerRmi(TestCow.class, TestCowImpl.class); - - final Server server = new Server(configuration); - server.setIdleTimeout(0); - - // register this object as a global object that the client will get - SERVER_GLOBAL_OBJECT_ID = server.createGlobalObject(globalRemoteServerObject); - - addEndPoint(server); - server.bind(false); - - server.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - connection.getRemoteObject(CLIENT_GLOBAL_OBJECT_ID, new RemoteObjectCallback() { - @Override - public - void created(final TestCow remoteObject) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - @Override - public - void run() { - System.err.println("Running test for: Server (LOCAL) -> Client (REMOTE)"); - runTest(connection, globalRemoteClientObject, remoteObject, CLIENT_GLOBAL_OBJECT_ID); - System.err.println("Done with test for: Server (LOCAL) -> Client (REMOTE)"); - } - }.start(); - } - }); - } - }); - - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, MessageWithTestCow m) { - System.err.println("Received finish signal for test for: Client (LOCAL) -> Server (REMOTE)"); - - TestCow object = m.getTestCow(); - final int id = object.id(); - assertEquals(SERVER_GLOBAL_OBJECT_ID, id); - - System.err.println("Finished test for: Client (LOCAL) -> Server (REMOTE)"); - - stopEndPoints(2000); - } - }); - - - // ---- - configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - // NOTICE: none of the super classes/interfaces are registered! - configuration.serialization.registerRmi(TestCow.class, TestCowImpl.class); - - - final Client client = new Client(configuration); - client.setIdleTimeout(0); - - - // register this object as a global object that the server will get - CLIENT_GLOBAL_OBJECT_ID = client.createGlobalObject(globalRemoteClientObject); - - addEndPoint(client); - - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(final Connection connection, MessageWithTestCow m) { - System.err.println("Received finish signal for test for: Server (LOCAL) -> Client (REMOTE)"); - - // this TestCow object should be the implementation, not the proxy. - TestCow object = m.getTestCow(); - final int id = object.id(); - assertEquals(CLIENT_GLOBAL_OBJECT_ID, id); - - System.err.println("Finished test for: Server (LOCAL) -> Client (REMOTE)"); - - // normally this is in the 'connected', but we do it here, so that it's more linear and easier to debug - connection.getRemoteObject(SERVER_GLOBAL_OBJECT_ID, new RemoteObjectCallback() { - @Override - public - void created(final TestCow remoteObject) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - @Override - public - void run() { - System.err.println("Running test for: Client (LOCAL) -> Server (REMOTE)"); - runTest(connection, globalRemoteServerObject, remoteObject, SERVER_GLOBAL_OBJECT_ID); - System.err.println("Done with test for: Client (LOCAL) -> Server (REMOTE)"); - } - }.start(); - } - }); - } - }); - - client.connect(5000); - waitForThreads(); - } - - private static - class ConnectionAware { - private - ConnectionImpl connection; - - public - ConnectionImpl getConnection() { - return connection; - } - - public - void setConnection(final ConnectionImpl connection) { - this.connection = connection; - } - } - - - private static - class TestCowImpl extends ConnectionAware implements TestCow { - public long value = System.currentTimeMillis(); - public int moos; - private final int id = 0; // the RMI id should be == to this for each direction. - - public - TestCowImpl() { - } - - @Override - public - void throwException() { - throw new UnsupportedOperationException("Why would I do that?"); - } - - @Override - public - void moo() { - this.moos++; - System.out.println("Moo!"); - } - - @Override - public - void moo(String value) { - this.moos += 2; - System.out.println("Moo: " + value); - } - - @Override - public - void moo(String value, long delay) { - this.moos += 4; - System.out.println("Moo: " + value + " (" + delay + ")"); - try { - Thread.sleep(delay); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @Override - public - int id() { - return id; - } - - @Override - public - float slow() { - System.out.println("Slowdown!!"); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return 123.0F; - } - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/RmiInitValidationTest.java b/test/dorkbox/network/not-fixed/rmi/RmiInitValidationTest.java deleted file mode 100644 index c6685fd0..00000000 --- a/test/dorkbox/network/not-fixed/rmi/RmiInitValidationTest.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright 2016 dorkbox, llc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright (c) 2008, Nathan Sweet - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the distribution. - * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.IOException; - -import org.junit.Test; - -import dorkbox.network.BaseTest; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.Server; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.NetworkSerializationManager; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -@SuppressWarnings("Duplicates") -public -class RmiInitValidationTest extends BaseTest { - - @Test - public - void rmiNetwork() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.tcpPort = tcpPort; - configuration.host = host; - } - }); - } - - @Test - public - void rmiLocal() throws SecurityException, IOException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - } - }); - } - - void register(final NetworkSerializationManager serialization) { - serialization.register(Command1.class); - serialization.register(Command2.class); - serialization.register(Command3.class); - serialization.register(Command4.class); - serialization.register(Command5.class); - serialization.register(Command6.class); - serialization.register(Command7.class); - serialization.register(Command8.class); - serialization.register(Command9.class); - serialization.register(Command10.class); - serialization.register(Command20.class); - serialization.register(Command30.class); - serialization.register(Command40.class); - serialization.register(Command50.class); - serialization.register(Command60.class); - serialization.register(Command70.class); - serialization.register(Command80.class); - serialization.register(Command90.class); - serialization.register(Command11.class); - serialization.register(Command12.class); - serialization.register(Command13.class); - serialization.register(Command14.class); - serialization.register(Command15.class); - serialization.register(Command16.class); - serialization.register(Command17.class); - serialization.register(Command18.class); - serialization.register(Command19.class); - serialization.register(Command21.class); - serialization.register(Command22.class); - serialization.register(Command23.class); - serialization.register(Command24.class); - serialization.register(Command25.class); - serialization.register(Command26.class); - serialization.register(Command27.class); - serialization.register(Command28.class); - serialization.register(Command29.class); - serialization.register(Command31.class); - serialization.register(Command32.class); - serialization.register(Command33.class); - serialization.register(Command34.class); - serialization.register(Command35.class); - serialization.register(Command36.class); - serialization.register(Command37.class); - serialization.register(Command38.class); - serialization.register(Command39.class); - serialization.register(Command41.class); - serialization.register(Command42.class); - serialization.register(Command43.class); - serialization.register(Command44.class); - serialization.register(Command45.class); - serialization.register(Command46.class); - serialization.register(Command47.class); - serialization.register(Command48.class); - serialization.register(Command49.class); - serialization.register(Command51.class); - serialization.register(Command52.class); - serialization.register(Command53.class); - serialization.register(Command54.class); - serialization.register(Command55.class); - serialization.register(Command56.class); - serialization.register(Command57.class); - serialization.register(Command58.class); - serialization.register(Command59.class); - serialization.register(Command61.class); - serialization.register(Command62.class); - serialization.register(Command63.class); - serialization.register(Command64.class); - serialization.register(Command65.class); - serialization.register(Command66.class); - serialization.register(Command67.class); - serialization.register(Command68.class); - serialization.register(Command69.class); - serialization.register(Command71.class); - serialization.register(Command72.class); - serialization.register(Command73.class); - serialization.register(Command74.class); - serialization.register(Command75.class); - serialization.register(Command76.class); - serialization.register(Command77.class); - serialization.register(Command78.class); - serialization.register(Command79.class); - serialization.register(Command81.class); - serialization.register(Command82.class); - serialization.register(Command83.class); - serialization.register(Command84.class); - serialization.register(Command85.class); - serialization.register(Command86.class); - serialization.register(Command87.class); - serialization.register(Command88.class); - serialization.register(Command89.class); - serialization.register(Command91.class); - serialization.register(Command92.class); - serialization.register(Command93.class); - serialization.register(Command94.class); - serialization.register(Command95.class); - serialization.register(Command96.class); - serialization.register(Command97.class); - serialization.register(Command98.class); - serialization.register(Command99.class); - serialization.register(Command100.class); - - serialization.register(Command101.class); - serialization.register(Command102.class); - serialization.register(Command103.class); - serialization.register(Command104.class); - serialization.register(Command105.class); - serialization.register(Command106.class); - serialization.register(Command107.class); - serialization.register(Command108.class); - serialization.register(Command109.class); - serialization.register(Command110.class); - serialization.register(Command120.class); - serialization.register(Command130.class); - serialization.register(Command140.class); - serialization.register(Command150.class); - serialization.register(Command160.class); - serialization.register(Command170.class); - serialization.register(Command180.class); - serialization.register(Command190.class); - serialization.register(Command111.class); - serialization.register(Command112.class); - serialization.register(Command113.class); - serialization.register(Command114.class); - serialization.register(Command115.class); - serialization.register(Command116.class); - serialization.register(Command117.class); - serialization.register(Command118.class); - serialization.register(Command119.class); - serialization.register(Command121.class); - serialization.register(Command122.class); - serialization.register(Command123.class); - serialization.register(Command124.class); - serialization.register(Command125.class); - serialization.register(Command126.class); - serialization.register(Command127.class); - serialization.register(Command128.class); - serialization.register(Command129.class); - serialization.register(Command131.class); - serialization.register(Command132.class); - serialization.register(Command133.class); - serialization.register(Command134.class); - serialization.register(Command135.class); - serialization.register(Command136.class); - serialization.register(Command137.class); - serialization.register(Command138.class); - serialization.register(Command139.class); - serialization.register(Command141.class); - serialization.register(Command142.class); - serialization.register(Command143.class); - serialization.register(Command144.class); - serialization.register(Command145.class); - serialization.register(Command146.class); - serialization.register(Command147.class); - serialization.register(Command148.class); - serialization.register(Command149.class); - serialization.register(Command151.class); - serialization.register(Command152.class); - serialization.register(Command153.class); - serialization.register(Command154.class); - serialization.register(Command155.class); - serialization.register(Command156.class); - serialization.register(Command157.class); - serialization.register(Command158.class); - serialization.register(Command159.class); - serialization.register(Command161.class); - serialization.register(Command162.class); - serialization.register(Command163.class); - serialization.register(Command164.class); - serialization.register(Command165.class); - serialization.register(Command166.class); - serialization.register(Command167.class); - serialization.register(Command168.class); - serialization.register(Command169.class); - serialization.register(Command171.class); - serialization.register(Command172.class); - serialization.register(Command173.class); - serialization.register(Command174.class); - serialization.register(Command175.class); - serialization.register(Command176.class); - serialization.register(Command177.class); - serialization.register(Command178.class); - serialization.register(Command179.class); - serialization.register(Command181.class); - serialization.register(Command182.class); - serialization.register(Command183.class); - serialization.register(Command184.class); - serialization.register(Command185.class); - serialization.register(Command186.class); - serialization.register(Command187.class); - serialization.register(Command188.class); - serialization.register(Command189.class); - serialization.register(Command191.class); - serialization.register(Command192.class); - serialization.register(Command193.class); - serialization.register(Command194.class); - serialization.register(Command195.class); - serialization.register(Command196.class); - serialization.register(Command197.class); - serialization.register(Command198.class); - serialization.register(Command199.class); - - serialization.register(FinishedCommand.class); - } - - /** - * In this test the server has two objects in an object space. The client - * uses the first remote object to get the second remote object. - */ - public - void rmi(final Config config) throws SecurityException, IOException { - Configuration configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Server server = new Server(configuration); - server.setIdleTimeout(0); - - - addEndPoint(server); - server.bind(false); - - - server.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, FinishedCommand object) { - stopEndPoints(); - } - }); - - // ---- - configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - - - Client client = new Client(configuration); - client.setIdleTimeout(0); - - addEndPoint(client); - client.listeners() - .add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - @Override - public - void run() { - connection.send() - .TCP(new FinishedCommand()) - .flush(); - } - }.start(); - } - }); - - client.connect(0); - - waitForThreads(); - } - - private static class Command1 {} - private static class Command2 {} - private static class Command3 {} - private static class Command4 {} - private static class Command5 {} - private static class Command6 {} - private static class Command7 {} - private static class Command8 {} - private static class Command9 {} - - private static class Command10 {} - private static class Command20 {} - private static class Command30 {} - private static class Command40 {} - private static class Command50 {} - private static class Command60 {} - private static class Command70 {} - private static class Command80 {} - private static class Command90 {} - - private static class Command11 {} - private static class Command12 {} - private static class Command13 {} - private static class Command14 {} - private static class Command15 {} - private static class Command16 {} - private static class Command17 {} - private static class Command18 {} - private static class Command19 {} - - private static class Command21 {} - private static class Command22 {} - private static class Command23 {} - private static class Command24 {} - private static class Command25 {} - private static class Command26 {} - private static class Command27 {} - private static class Command28 {} - private static class Command29 {} - - private static class Command31 {} - private static class Command32 {} - private static class Command33 {} - private static class Command34 {} - private static class Command35 {} - private static class Command36 {} - private static class Command37 {} - private static class Command38 {} - private static class Command39 {} - - private static class Command41 {} - private static class Command42 {} - private static class Command43 {} - private static class Command44 {} - private static class Command45 {} - private static class Command46 {} - private static class Command47 {} - private static class Command48 {} - private static class Command49 {} - - private static class Command51 {} - private static class Command52 {} - private static class Command53 {} - private static class Command54 {} - private static class Command55 {} - private static class Command56 {} - private static class Command57 {} - private static class Command58 {} - private static class Command59 {} - - private static class Command61 {} - private static class Command62 {} - private static class Command63 {} - private static class Command64 {} - private static class Command65 {} - private static class Command66 {} - private static class Command67 {} - private static class Command68 {} - private static class Command69 {} - - private static class Command71 {} - private static class Command72 {} - private static class Command73 {} - private static class Command74 {} - private static class Command75 {} - private static class Command76 {} - private static class Command77 {} - private static class Command78 {} - private static class Command79 {} - - private static class Command81 {} - private static class Command82 {} - private static class Command83 {} - private static class Command84 {} - private static class Command85 {} - private static class Command86 {} - private static class Command87 {} - private static class Command88 {} - private static class Command89 {} - - private static class Command91 {} - private static class Command92 {} - private static class Command93 {} - private static class Command94 {} - private static class Command95 {} - private static class Command96 {} - private static class Command97 {} - private static class Command98 {} - private static class Command99 {} - - - - private static class Command100 {} - private static class Command101 {} - private static class Command102 {} - private static class Command103 {} - private static class Command104 {} - private static class Command105 {} - private static class Command106 {} - private static class Command107 {} - private static class Command108 {} - private static class Command109 {} - - private static class Command110 {} - private static class Command120 {} - private static class Command130 {} - private static class Command140 {} - private static class Command150 {} - private static class Command160 {} - private static class Command170 {} - private static class Command180 {} - private static class Command190 {} - - private static class Command111 {} - private static class Command112 {} - private static class Command113 {} - private static class Command114 {} - private static class Command115 {} - private static class Command116 {} - private static class Command117 {} - private static class Command118 {} - private static class Command119 {} - - private static class Command121 {} - private static class Command122 {} - private static class Command123 {} - private static class Command124 {} - private static class Command125 {} - private static class Command126 {} - private static class Command127 {} - private static class Command128 {} - private static class Command129 {} - - private static class Command131 {} - private static class Command132 {} - private static class Command133 {} - private static class Command134 {} - private static class Command135 {} - private static class Command136 {} - private static class Command137 {} - private static class Command138 {} - private static class Command139 {} - - private static class Command141 {} - private static class Command142 {} - private static class Command143 {} - private static class Command144 {} - private static class Command145 {} - private static class Command146 {} - private static class Command147 {} - private static class Command148 {} - private static class Command149 {} - - private static class Command151 {} - private static class Command152 {} - private static class Command153 {} - private static class Command154 {} - private static class Command155 {} - private static class Command156 {} - private static class Command157 {} - private static class Command158 {} - private static class Command159 {} - - private static class Command161 {} - private static class Command162 {} - private static class Command163 {} - private static class Command164 {} - private static class Command165 {} - private static class Command166 {} - private static class Command167 {} - private static class Command168 {} - private static class Command169 {} - - private static class Command171 {} - private static class Command172 {} - private static class Command173 {} - private static class Command174 {} - private static class Command175 {} - private static class Command176 {} - private static class Command177 {} - private static class Command178 {} - private static class Command179 {} - - private static class Command181 {} - private static class Command182 {} - private static class Command183 {} - private static class Command184 {} - private static class Command185 {} - private static class Command186 {} - private static class Command187 {} - private static class Command188 {} - private static class Command189 {} - - private static class Command191 {} - private static class Command192 {} - private static class Command193 {} - private static class Command194 {} - private static class Command195 {} - private static class Command196 {} - private static class Command197 {} - private static class Command198 {} - private static class Command199 {} - - - private static class FinishedCommand {} -} diff --git a/test/dorkbox/network/not-fixed/rmi/RmiObjectIdExhaustionTest.java b/test/dorkbox/network/not-fixed/rmi/RmiObjectIdExhaustionTest.java deleted file mode 100644 index 36eaced6..00000000 --- a/test/dorkbox/network/not-fixed/rmi/RmiObjectIdExhaustionTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2018 dorkbox, llc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; - -import dorkbox.network.BaseTest; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.Server; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.EndPoint; -import dorkbox.network.connection.Listener; -import dorkbox.network.serialization.NetworkSerializationManager; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -public -class RmiObjectIdExhaustionTest extends BaseTest { - - // start at 1 because we are testing connection local RMI objects, which start at 1 - private AtomicInteger objectCounter = new AtomicInteger(1); - - public static - void register(NetworkSerializationManager manager) { - manager.register(Object.class); // Needed for Object#toString, hashCode, etc. - manager.register(MessageWithTestCow.class); - manager.register(UnsupportedOperationException.class); - } - - // @Test // NOTE: remove final from RmiBridge.INVALID_RMI to test! - public - void rmiNetwork() throws SecurityException, IOException, InterruptedException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.tcpPort = tcpPort; - configuration.udpPort = udpPort; - configuration.host = host; - } - }); - - // have to reset the object ID counter - TestCowImpl.ID_COUNTER.set(1); - - Thread.sleep(2000L); - } - - // @Test // NOTE: remove final from RmiBridge.INVALID_RMI to test! - public - void rmiLocal() throws SecurityException, IOException, InterruptedException { - rmi(new Config() { - @Override - public - void apply(final Configuration configuration) { - configuration.localChannelName = EndPoint.LOCAL_CHANNEL; - } - }); - - // have to reset the object ID counter - TestCowImpl.ID_COUNTER.set(1); - - Thread.sleep(2000L); - } - - - public - void rmi(final Config config) throws SecurityException, IOException { - // NOTE: remove final from RmiBridge.INVALID_RMI to test! - // RmiBridge.INVALID_RMI = 4; - - Configuration configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - configuration.serialization.registerRmi(TestCow.class, TestCowImpl.class); - - final Server server = new Server(configuration); - server.setIdleTimeout(0); - - addEndPoint(server); - server.bind(false); - - - - - // ---- - configuration = new Configuration(); - config.apply(configuration); - - configuration.serialization = Serialization.DEFAULT(); - register(configuration.serialization); - configuration.serialization.registerRmi(TestCow.class, TestCowImpl.class); - - - final Client client = new Client(configuration); - client.setIdleTimeout(0); - - addEndPoint(client); - - - client.listeners().add(new Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - iterate(objectCounter.getAndAdd(2), connection); - } - }); - - client.listeners() - .add(new Listener.OnMessageReceived() { - @Override - public - void received(Connection connection, MessageWithTestCow m) { - - } - }); - - client.connect(5000); - - waitForThreads(); - } - - private void iterate(final int currentCount, final Connection connection) { - // if this is called in the dispatch thread, it will block network comms while waiting for a response and it won't work... - connection.createRemoteObject(TestCow.class, new RemoteObjectCallback() { - @Override - public - void created(final TestCow remoteObject) { - if (remoteObject != null) { - System.out.println("valid ID " + currentCount); - - iterate(objectCounter.getAndAdd(2), connection); - } - else { - System.out.println("invalid ID " + currentCount); - stopEndPoints(); - } - } - }); - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/multiJVM/TestClient.java b/test/dorkbox/network/not-fixed/rmi/multiJVM/TestClient.java deleted file mode 100644 index 49760b12..00000000 --- a/test/dorkbox/network/not-fixed/rmi/multiJVM/TestClient.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2019 dorkbox, llc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.slf4j.LoggerFactory; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.encoder.PatternLayoutEncoder; -import ch.qos.logback.classic.joran.JoranConfigurator; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.ConsoleAppender; -import dorkbox.network.Client; -import dorkbox.network.Configuration; -import dorkbox.network.connection.Connection; -import dorkbox.network.rmi.RemoteObjectCallback; -import dorkbox.network.rmi.RmiTest; -import dorkbox.network.rmi.TestCow; -import dorkbox.network.serialization.Serialization; -import io.netty.util.ResourceLeakDetector; - -/** - * - */ -public -class TestClient -{ - public static void setup() { - ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); - - // assume SLF4J is bound to logback in the current environment - Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); - LoggerContext context = rootLogger.getLoggerContext(); - - JoranConfigurator jc = new JoranConfigurator(); - jc.setContext(context); - context.reset(); // override default configuration - -// rootLogger.setLevel(Level.OFF); - - // rootLogger.setLevel(Level.DEBUG); - rootLogger.setLevel(Level.TRACE); -// rootLogger.setLevel(Level.ALL); - - - // we only want error messages - Logger nettyLogger = (Logger) LoggerFactory.getLogger("io.netty"); - nettyLogger.setLevel(Level.ERROR); - - // we only want error messages - Logger kryoLogger = (Logger) LoggerFactory.getLogger("com.esotericsoftware"); - kryoLogger.setLevel(Level.ERROR); - - PatternLayoutEncoder encoder = new PatternLayoutEncoder(); - encoder.setContext(context); - encoder.setPattern("%date{HH:mm:ss.SSS} %-5level [%logger{35}] %msg%n"); - encoder.start(); - - ConsoleAppender consoleAppender = new ch.qos.logback.core.ConsoleAppender(); - - consoleAppender.setContext(context); - consoleAppender.setEncoder(encoder); - consoleAppender.start(); - - rootLogger.addAppender(consoleAppender); - } - - - public static - void main(String[] args) { - setup(); - - Configuration configuration = new Configuration(); - configuration.tcpPort = 2000; - configuration.udpPort = 2001; - configuration.host = "localhost"; - - configuration.serialization = Serialization.DEFAULT(); - RmiTest.register(configuration.serialization); - - try { - final Client client = new Client(configuration); - client.disableRemoteKeyValidation(); - client.setIdleTimeout(0); - - client.listeners() - .add(new dorkbox.network.connection.Listener.OnConnected() { - @Override - public - void connected(final Connection connection) { - System.err.println("Starting test for: Client -> Server"); - - // if this is called in the dispatch thread, it will block network comms while waiting for a response and it won't work... - connection.createRemoteObject(TestCow.class, new RemoteObjectCallback() { - @Override - public - void created(final TestCow remoteObject) { - // MUST run on a separate thread because remote object method invocations are blocking - new Thread() { - @Override - public - void run() { - RmiTest.runTests(connection, remoteObject, 1); - - try { - Thread.sleep(1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - System.err.println("DONE"); - client.stop(); - } - }.start(); - } - }); - } - }); - - client.connect(3000); - client.waitForShutdown(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/test/dorkbox/network/not-fixed/rmi/multiJVM/TestServer.java b/test/dorkbox/network/not-fixed/rmi/multiJVM/TestServer.java deleted file mode 100644 index 4a9cc0db..00000000 --- a/test/dorkbox/network/not-fixed/rmi/multiJVM/TestServer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019 dorkbox, llc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import dorkbox.network.Server; -import dorkbox.network.rmi.RmiTest; -import dorkbox.network.rmi.TestCow; -import dorkbox.network.rmi.TestCowImpl; -import dorkbox.network.serialization.Serialization; -import dorkbox.util.exceptions.SecurityException; - -/** - * - */ -public -class TestServer -{ - public static - void main(String[] args) { - TestClient.setup(); - - dorkbox.network.Configuration configuration = new dorkbox.network.Configuration(); - configuration.tcpPort = 2000; - configuration.udpPort = 2001; - - configuration.serialization = Serialization.DEFAULT(); - RmiTest.register(configuration.serialization); - - configuration.serialization.registerRmi(TestCow.class, TestCowImpl.class); - - Server server = null; - try { - server = new Server(configuration); - server.disableRemoteKeyValidation(); - } catch (SecurityException e) { - e.printStackTrace(); - } - - server.setIdleTimeout(0); - server.bind(true); - }}