summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidijus Vaisnora2012-01-03 10:05:13 (EST)
committerEgidijus Vaisnora2012-01-03 10:05:13 (EST)
commita76cac74647637305119e29fdb34453e81fabddf (patch)
treee7af7e4712ace63ea240d490e6b0a33e35cc147f
parent0807f4d85481435b3032bbffa5d16ff5073944cf (diff)
downloadcdo-a76cac74647637305119e29fdb34453e81fabddf.zip
cdo-a76cac74647637305119e29fdb34453e81fabddf.tar.gz
cdo-a76cac74647637305119e29fdb34453e81fabddf.tar.bz2
Changed disconnection flow for test.
Empty buffer dispatched only when channel is closed and before the check for the signal completion.
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestExitFromReadWait.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitIndication.java3
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/WaitRequest.java26
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java27
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 62574a2..81046f0 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 f541d8d..63206c4 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 73c38f0..1c491d8 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 41c3ec6..3e68391 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();