Skip to content

Commit

Permalink
Merge pull request #12 from mohrezaei/master
Browse files Browse the repository at this point in the history
Add a stopAndTerminateConnections method to socket server.
  • Loading branch information
mohrezaei authored Jul 24, 2022
2 parents 11ef4e9 + 55d440d commit 731b9dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
## 5.1.3 2022-07-24
- for socket server, add a method to terminate ongoing connections (usually after stop)

## 5.1.2 2019-11-05
- for socket server, fix url to service local map
- for socket server, fix socket initial connection timeout
Expand Down
2 changes: 1 addition & 1 deletion build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<tstamp>
<format property="TIME_NOW" pattern="hh:mm:ss a z"/>
</tstamp>
<echo message="JUnit master suite for jrpip starting at ${TIME_NOW} on ${TODAY} with ${test.threads} jvms."/>
<echo message="JUnit master suite for jrpip starting at ${TIME_NOW} on ${TODAY}."/>
<echo message="Log4j file: ${root}/src/test/resources/log4j.properties"/>
<junit printSummary="yes" haltonerror="true" haltonfailure="true" fork="true" dir="${root}/target/testresult">
<formatter type="xml" />
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/gs/jrpip/server/SocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,21 @@ public void stop()
}
}

public void stopAndTerminateConnections()
{
this.stop();
this.terminateConnections();
}

public void terminateConnections()
{
for (ServerSocketHandler ssh: this.hanlders.keySet())
{
try
{
ssh.socket.close();
} catch (Exception ignore)
}
catch (Exception ignore)
{

}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/gs/jrpip/SimpleSocketServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,23 @@ public void testServerRecycle() throws Exception
Assert.assertTrue(end - now < 100);

}

public void testTerminateServerSide() throws Exception
{
Echo echo = this.buildEchoProxy(100);

Assert.assertEquals("hello", echo.echo("hello"));

this.server.stopAndTerminateConnections();

try
{
echo.echo("hello");
Assert.fail("Must not get here");
}
catch(JrpipRuntimeException exception)
{
// expected
}
}
}

0 comments on commit 731b9dd

Please sign in to comment.