diff options
author | Egidijus Vaisnora | 2012-01-03 15:05:13 +0000 |
---|---|---|
committer | Egidijus Vaisnora | 2012-01-03 15:05:13 +0000 |
commit | a76cac74647637305119e29fdb34453e81fabddf (patch) | |
tree | e7af7e4712ace63ea240d490e6b0a33e35cc147f | |
parent | 0807f4d85481435b3032bbffa5d16ff5073944cf (diff) | |
download | cdo-a76cac74647637305119e29fdb34453e81fabddf.tar.gz cdo-a76cac74647637305119e29fdb34453e81fabddf.tar.xz cdo-a76cac74647637305119e29fdb34453e81fabddf.zip |
Changed disconnection flow for test.
Empty buffer dispatched only when channel is closed and before the
check for the signal completion.
4 files changed, 46 insertions, 12 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestExitFromReadWait.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestExitFromReadWait.java index 62574a26ec..81046f0274 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestExitFromReadWait.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestExitFromReadWait.java @@ -58,7 +58,7 @@ public class TestExitFromReadWait extends AbstractProtocolTest }).start(); latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); - assertEquals("Signal waits for input, but shouldn't", 0, latch.getCount()); + assertEquals("Signal waits for input, but it shouldn't.", 0, latch.getCount()); } finally { diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitIndication.java index f541d8def3..63206c41b1 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitIndication.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitIndication.java @@ -14,6 +14,8 @@ import org.eclipse.net4j.signal.IndicationWithResponse; import org.eclipse.net4j.util.io.ExtendedDataInputStream; import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import java.util.concurrent.TimeUnit; + /** * @author Egidijus Vaisnora */ @@ -34,5 +36,6 @@ public class WaitIndication extends IndicationWithResponse protected void responding(ExtendedDataOutputStream out) throws Exception { // Do not write anything + WaitRequest.getWriteSemaphore().await(30, TimeUnit.SECONDS); } } diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitRequest.java index 73c38f07d7..1c491d8d27 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitRequest.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitRequest.java @@ -10,30 +10,52 @@ */ package org.eclipse.net4j.tests.signal; +import org.eclipse.net4j.channel.IChannel; import org.eclipse.net4j.signal.RequestWithConfirmation; import org.eclipse.net4j.util.io.ExtendedDataInputStream; import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import java.util.concurrent.CountDownLatch; + /** * @author Egidijus Vaisnora */ public class WaitRequest extends RequestWithConfirmation<Integer> { + private static CountDownLatch writelatch; + public WaitRequest(TestSignalProtocol protocol) { super(protocol, TestSignalProtocol.SIGNAL_WITH_WAIT); } + public static CountDownLatch getWriteSemaphore() + { + return writelatch; + } + @Override protected void requesting(ExtendedDataOutputStream out) throws Exception { + writelatch = new CountDownLatch(1); out.writeInt(100); } @Override protected Integer confirming(ExtendedDataInputStream in) throws Exception { - getProtocol().getChannel().close(); - return in.readInt(); + final IChannel channel = getProtocol().getChannel(); + + new Thread(new Runnable() + { + public void run() + { + channel.close(); + writelatch.countDown(); + } + }).start(); + + int readValue = in.readInt(); + return readValue; } } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java index 41c3ec61a6..3e683910f6 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java @@ -268,6 +268,24 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i @Override
protected void doBeforeDeactivate() throws Exception
{
+
+ IChannel channel = getChannel();
+ if (channel != null && channel.isClosed())
+ {
+ // deliver to signals empty buffers
+ synchronized (signals)
+ {
+ for (Iterator<Signal> it = signals.values().iterator(); it.hasNext();)
+ {
+ BufferInputStream bufferInputStream = it.next().getBufferInputStream();
+ if (bufferInputStream != null)
+ {
+ bufferInputStream.handleBuffer(new EOSBuffer(channel.getID()));
+ }
+ }
+ }
+ }
+
synchronized (signals)
{
// Wait at most 10 seconds for running signals to finish
@@ -286,15 +304,6 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i IChannel channel = getChannel();
if (channel != null)
{
- for (Iterator<Signal> it = signals.values().iterator(); it.hasNext();)
- {
- BufferInputStream bufferInputStream = it.next().getBufferInputStream();
- if (bufferInputStream != null)
- {
- bufferInputStream.handleBuffer(new EOSBuffer(channel.getID()));
- }
- }
-
synchronized (signals)
{
signals.clear();
|