Skip to content

Commit

Permalink
ns
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Apr 29, 2009
1 parent e98e213 commit a19fa59
Showing 1 changed file with 53 additions and 3 deletions.
@@ -1,6 +1,8 @@
package org.jgroups.tests;

import org.jgroups.*;
import org.jgroups.stack.Protocol;
import org.jgroups.stack.ProtocolStack;
import org.jgroups.protocols.UNICAST;
import org.jgroups.util.Util;
import org.testng.annotations.AfterMethod;
Expand All @@ -13,7 +15,7 @@
/**
* Tests unilateral closings of UNICAST connections. The test scenarios are described in doc/design.UNICAST.new.txt.
* @author Bela Ban
* @version $Id: UNICAST_ConnectionTests.java,v 1.5 2009/04/29 04:56:35 belaban Exp $
* @version $Id: UNICAST_ConnectionTests.java,v 1.6 2009/04/29 05:20:00 belaban Exp $
*/
@Test(groups=Global.FUNCTIONAL,sequential=false)
public class UNICAST_ConnectionTests {
Expand Down Expand Up @@ -72,7 +74,7 @@ public void testBothChannelsClosing() throws Exception {


/**
* Scenario #4 (A closes the connection unilaterally (B keeps it open), then reopens it and sends a message)
* Scenario #4 (A closes the connection unilaterally (B keeps it open), then reopens it and sends messages)
*/
public void testAClosingUnilaterally() throws Exception {
sendToEachOtherAndCheck(10);
Expand All @@ -86,7 +88,7 @@ public void testAClosingUnilaterally() throws Exception {
}

/**
* Scenario #5 (B closes the connection unilaterally (A keeps it open), then A sends a message to B)
* Scenario #5 (B closes the connection unilaterally (A keeps it open), then A sends messages to B)
*/
public void testBClosingUnilaterally() throws Exception {
sendToEachOtherAndCheck(10);
Expand All @@ -100,6 +102,27 @@ public void testBClosingUnilaterally() throws Exception {
}


/**
* Scenario #6 (A closes the connection unilaterally (B keeps it open), then reopens it and sends messages,
* but loses the firts message
*/
public void testAClosingUnilaterallyButLosingFirstMessage() throws Exception {
sendToEachOtherAndCheck(10);

// now close connection on A unilaterally
System.out.println("==== Closing the connection on A");
u1.removeConnection(b_addr);

// add a Drop protocol to drop the first unicast message
Drop drop=new Drop(true);
a.getProtocolStack().insertProtocol(drop, ProtocolStack.BELOW, UNICAST.class);

// then send messages from A to B
sendAndCheck(a, b_addr, 10, r2);
}



/**
* Send num unicasts on both channels and verify the other end received them
* @param num
Expand Down Expand Up @@ -167,4 +190,31 @@ public String toString() {
return name;
}
}

private static class Drop extends Protocol {
private volatile boolean drop_next=false;

private Drop() {
}

private Drop(boolean drop_next) {
this.drop_next=drop_next;
}

public String getName() {
return "Drop";
}

public void dropNext() {
drop_next=true;
}

public Object down(Event evt) {
if(drop_next && evt.getType() == Event.MSG) {
drop_next=false;
return null;
}
return super.down(evt);
}
}
}

0 comments on commit a19fa59

Please sign in to comment.