Skip to content

Commit

Permalink
Moved
Browse files Browse the repository at this point in the history
  • Loading branch information
dreedyman committed Sep 21, 2021
1 parent b83b718 commit a5f4d83
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.rioproject.net;
package org.rioproject.rmi;

import java.net.UnknownHostException;
import net.jini.jeri.*;
import net.jini.jeri.tcp.TcpEndpoint;
import net.jini.jeri.tcp.TcpServerEndpoint;
import org.junit.Assert;
import org.junit.Test;
import org.rioproject.net.PortRangeServerSocketFactory;

import java.io.IOException;
import java.net.ServerSocket;
Expand Down Expand Up @@ -79,10 +80,10 @@ public void verifyPortRangeEquality() {
t = e;
}
Assert.assertNull(t);
Assert.assertTrue(pr1.equals(pr2));
Assert.assertTrue(pr2.equals(pr1));
Assert.assertTrue(pr1.equals(pr1));
Assert.assertTrue(pr2.equals(pr2));
Assert.assertEquals(pr1, pr2);
Assert.assertEquals(pr2, pr1);
Assert.assertEquals(pr1, pr1);
Assert.assertEquals(pr2, pr2);
}

@Test
Expand Down Expand Up @@ -110,7 +111,7 @@ public void verifyPortRangeHashCode() {
@Test
public void verifyServerSocketsWithinRange() {
PortRangeServerSocketFactory range = new PortRangeServerSocketFactory(49152, 49155);
List<ServerSocket> serverSockets = new ArrayList<ServerSocket>();
List<ServerSocket> serverSockets = new ArrayList<>();
Throwable t = null;
while(t==null) {
try {
Expand All @@ -132,10 +133,10 @@ public void verifyServerSocketsWithinRange() {
@Test
public void createPortRangeWithStartRangeOnly() {
PortRangeServerSocketFactory range = new PortRangeServerSocketFactory(65530);
Assert.assertTrue(range.getEnd()==PortRangeServerSocketFactory.RANGE_END);
List<ServerSocket> serverSockets = new ArrayList<ServerSocket>();
Assert.assertEquals(range.getEnd(), PortRangeServerSocketFactory.RANGE_END);
List<ServerSocket> serverSockets = new ArrayList<>();
Throwable t = null;
while(t==null) {
while (t == null) {
try {
ServerSocket s = range.createServerSocket(0);
serverSockets.add(s);
Expand All @@ -144,7 +145,7 @@ public void createPortRangeWithStartRangeOnly() {
}
}
Assert.assertNotNull(t);
Assert.assertTrue("Should have 6 ServerSockets", serverSockets.size()==6);
Assert.assertEquals("Should have 6 ServerSockets", 6, serverSockets.size());
for (ServerSocket s : serverSockets) {
int port = s.getLocalPort();
Assert.assertTrue("Port "+port+" should be >= "+range.getStart(), port >= range.getStart());
Expand All @@ -156,8 +157,8 @@ public void createPortRangeWithStartRangeOnly() {
public void createBasicJeriExporter() throws UnknownHostException {
Throwable t = null;
PortRangeServerSocketFactory range = null;
List<Endpoint> endPoints = new ArrayList<Endpoint>();
String host = getHostAddressFromProperty("java.rmi.server.hostname");
List<Endpoint> endPoints = new ArrayList<>();
String host = getHostAddressFromProperty();
for(int i=0; i<500; i++) {
try {
range = new PortRangeServerSocketFactory(10000, 10500);
Expand All @@ -176,7 +177,7 @@ public void createBasicJeriExporter() throws UnknownHostException {
}
Assert.assertNull(t);
Assert.assertNotNull(range);
Assert.assertTrue(endPoints.size()==500);
Assert.assertEquals(500, endPoints.size());
for(Endpoint e : endPoints) {
Assert.assertTrue(e instanceof TcpEndpoint);
int port = ((TcpEndpoint)e).getPort();
Expand All @@ -195,24 +196,22 @@ String getHostAddress() throws java.net.UnknownHostException {
* property is not resolvable, return the default host address obtained from
* {@link java.net.InetAddress#getLocalHost()}
*
* @param property The property name to use
*
* @return The local host address
*
* @throws java.net.UnknownHostException if no IP address for the host name
* could be found.
*/
String getHostAddressFromProperty(String property) throws java.net.UnknownHostException {
String getHostAddressFromProperty() throws java.net.UnknownHostException {
String host = getHostAddress();
String value = System.getProperty(property);
if(value != null) {
String value = System.getProperty("java.rmi.server.hostname");
if (value != null) {
host = java.net.InetAddress.getByName(value).getHostAddress();
}
return(host);
return host;
}

class EndpointContext implements ServerEndpoint.ListenContext {
List<ServerEndpoint.ListenEndpoint> endpoints = new ArrayList<ServerEndpoint.ListenEndpoint>();
static class EndpointContext implements ServerEndpoint.ListenContext {
List<ServerEndpoint.ListenEndpoint> endpoints = new ArrayList<>();

@Override
public ServerEndpoint.ListenCookie addListenEndpoint(ServerEndpoint.ListenEndpoint lep) throws IOException {
Expand All @@ -222,7 +221,7 @@ public ServerEndpoint.ListenCookie addListenEndpoint(ServerEndpoint.ListenEndpoi
}


private class Dispatcher implements RequestDispatcher {
private static class Dispatcher implements RequestDispatcher {
public void dispatch(InboundRequest request) {
/*try {
Thread.sleep(5000);
Expand Down

0 comments on commit a5f4d83

Please sign in to comment.