Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void detach(

public void close()
{
capacity.decrementAndGet();
capacity.incrementAndGet();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.rules.RuleChain.outerRule;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

Expand Down Expand Up @@ -352,21 +355,61 @@ public void shouldWriteDataAfterReceiveEnd() throws Exception
value = "2")
public void shouldResetWhenConnectionsExceeded() throws Exception
{
try (ServerSocketChannel server = ServerSocketChannel.open())
try (ServerSocketChannel server = ServerSocketChannel.open();
Selector selector = Selector.open())
{
server.configureBlocking(false);
server.setOption(SO_REUSEADDR, true);
server.bind(new InetSocketAddress("127.0.0.1", 12345));
server.register(selector, SelectionKey.OP_ACCEPT);

k3po.start();

for (int i = 1; i < 3; i++)
AcceptHandler handler = channel ->
{
channel.configureBlocking(true);
channel.close();
};

int accepted = 0;
while (accepted < 2)
{
try (SocketChannel channel = server.accept())
selector.select();
for (SelectionKey key : selector.selectedKeys())
{
if (key.isAcceptable())
{
SocketChannel client = server.accept();
handler.handle(client);
accepted++;
}
}

if (accepted == 2)
{
k3po.notifyBarrier("CONNECTION_ACCEPTED_" + i);
k3po.notifyBarrier("CONNECTION_ACCEPTED_1");
k3po.notifyBarrier("CONNECTION_ACCEPTED_2");
}
}

accepted = 0;
while (accepted < 2)
{
selector.select();
for (SelectionKey key : selector.selectedKeys())
{
if (key.isAcceptable())
{
SocketChannel client = server.accept();
handler.handle(client);
accepted++;
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of accepted should equal 2 here?
Let's add an assertion to document that test requirement.

assert accepted == 2;

selector.selectedKeys().clear();
k3po.finish();
}
}
Expand All @@ -376,4 +419,10 @@ public static InetAddress[] resolveHost(
{
throw new UnknownHostException();
}

@FunctionalInterface
interface AcceptHandler
{
void handle(SocketChannel channel) throws IOException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@ write await CONNECTION_ACCEPTED_2
write close
read closed

read notify CONNECTION_CLOSED_2

connect "zilla://streams/app0"
option zilla:window 8192
option zilla:transmission "duplex"
connect aborted

connect await CONNECTION_CLOSED_2
"zilla://streams/app0"
option zilla:window 8192
option zilla:transmission "duplex"
connected
write close
read closed

connect await CONNECTION_CLOSED_2
"zilla://streams/app0"
option zilla:window 8192
option zilla:transmission "duplex"
connected
write close
read closed
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ write close
write notify CLOSED

rejected

accepted
connected
read closed
write close

accepted
connected
read closed
write close
Loading