Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- local address in DISCARD is dynamically fetched from JChannel if nu…

…ll (https://issues.jboss.org/browse/JGRP-1603)

- Added test by Dan Berindei
  • Loading branch information...
commit 40d43dbc3cac6f24802c1edba225b598e163706c 1 parent b6250a4
@belaban authored
View
23 src/org/jgroups/protocols/DISCARD.java
@@ -62,7 +62,12 @@
public DISCARD localAddress(Address addr) {setLocalAddress(addr); return this;}
- public Address localAddress() {return localAddress;}
+
+ public Address localAddress() {
+ if(localAddress == null)
+ localAddress=(Address)up_prot.up(new Event(Event.GET_LOCAL_ADDRESS));
+ return localAddress;
+ }
public boolean isDiscardAll() {
return discard_all;
@@ -135,7 +140,7 @@ public void startGui() {
if(discard_dialog == null) {
discard_dialog=new DiscardDialog();
discard_dialog.init();
- discard_dialog.setTitle(localAddress != null? localAddress.toString() : "n/a");
+ discard_dialog.setTitle(localAddress() != null? localAddress().toString() : "n/a");
discard_dialog.handleView(members);
}
}
@@ -200,10 +205,10 @@ public Object down(Event evt) {
boolean multicast=dest == null;
if(msg.getSrc() == null)
- msg.setSrc(localAddress);
+ msg.setSrc(localAddress());
if(discard_all) {
- if(dest == null || dest.equals(localAddress))
+ if(dest == null || dest.equals(localAddress()))
loopback(msg);
return null;
}
@@ -221,7 +226,7 @@ public Object down(Event evt) {
if(down > 0) {
r=Math.random();
if(r < down) {
- if(excludeItself && dest != null && dest.equals(localAddress)) {
+ if(excludeItself && dest != null && dest.equals(localAddress())) {
if(log.isTraceEnabled()) log.trace("excluding itself");
}
else {
@@ -256,7 +261,7 @@ public Object down(Event evt) {
/** Checks if a message should be passed up, or not */
protected boolean shouldDropUpMessage(Message msg, Address sender) {
- if(discard_all && !sender.equals(localAddress))
+ if(discard_all && !sender.equals(localAddress()))
return true;
if(ignoredMembers.contains(sender)) {
@@ -269,7 +274,7 @@ protected boolean shouldDropUpMessage(Message msg, Address sender) {
if(up > 0) {
double r=Math.random();
if(r < up) {
- if(excludeItself && sender.equals(localAddress)) {
+ if(excludeItself && sender.equals(localAddress())) {
if(log.isTraceEnabled())
log.trace("excluding myself");
}
@@ -289,7 +294,7 @@ protected boolean shouldDropUpMessage(Message msg, Address sender) {
private void loopback(Message msg) {
final Message rsp=msg.copy(true);
if(rsp.getSrc() == null)
- rsp.setSrc(localAddress);
+ rsp.setSrc(localAddress());
// pretty inefficient: creates one thread per message, okay for testing only
Thread thread=new Thread(new Runnable() {
@@ -328,7 +333,7 @@ void init() {
getContentPane().add(checkboxes);
pack();
setVisible(true);
- setTitle(localAddress != null? localAddress.toString() : "n/a");
+ setTitle(localAddress() != null? localAddress().toString() : "n/a");
}
View
96 tests/junit-functional/org/jgroups/tests/DynamicDiscardTest.java
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.jgroups.tests;
+
+import org.jgroups.Global;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.jgroups.blocks.MessageDispatcher;
+import org.jgroups.blocks.RequestHandler;
+import org.jgroups.blocks.RequestOptions;
+import org.jgroups.protocols.*;
+import org.jgroups.protocols.pbcast.GMS;
+import org.jgroups.protocols.pbcast.NAKACK2;
+import org.jgroups.protocols.pbcast.STABLE;
+import org.jgroups.stack.ProtocolStack;
+import org.jgroups.util.Rsp;
+import org.jgroups.util.RspList;
+import org.jgroups.util.Util;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Test the VERIFY_SUSPECT protocol combined with FD and DISCARD.
+ *
+ * @author Dan Berindei
+ * @since 3.3
+ */
+@Test(groups=Global.FUNCTIONAL)
+public class DynamicDiscardTest {
+ private static final int NUM = 2;
+
+ public void testLeaveDuringSend() throws Exception {
+ final JChannel[] channels = new JChannel[NUM];
+ final MessageDispatcher[] dispatchers = new MessageDispatcher[NUM];
+
+ for(int i=0; i < NUM; i++) {
+ channels[i]= new JChannel(new SHARED_LOOPBACK(),
+ new PING().timeout(1000).numInitialMembers(NUM),
+ new MERGE2(),
+ new FD().setValue("timeout", 1000).setValue("max_tries", 1),
+ new NAKACK2(),
+ new UNICAST3(),
+ new STABLE(),
+ new GMS(),
+ new RSVP().setValue("ack_on_delivery", false)
+ .setValue("throw_exception_on_timeout", false));
+ channels[i].setName(Character.toString((char) ('A' + i)));
+ channels[i].setDiscardOwnMessages(true);
+ dispatchers[i]=new MessageDispatcher(channels[i], null, null, new MyRequestHandler());
+ channels[i].connect("DynamicDiscardTest");
+ System.out.print(i + 1 + " ");
+ }
+ Util.waitUntilAllChannelsHaveSameSize(10000, 1000, channels);
+
+ // discard all messages (except those to self)
+ DISCARD discard = new DISCARD();
+ channels[0].getProtocolStack().insertProtocol(discard, ProtocolStack.ABOVE, TP.class);
+ discard.setDiscardAll(true);
+
+ // send a RSVP message
+ Message msg = new Message(null, "message2");
+ msg.setFlag(Message.RSVP, Message.OOB);
+ RspList<Object> rsps = dispatchers[0].castMessage(null, msg, RequestOptions.SYNC().setTimeout(5000));
+
+ Rsp<Object> objectRsp = rsps.get(channels[1].getAddress());
+ assertFalse(objectRsp.wasReceived());
+ assertTrue(objectRsp.wasSuspected());
+ }
+
+ private static class MyRequestHandler implements RequestHandler {
+ @Override
+ public Object handle(Message msg) throws Exception {
+ System.out.println(String.format("Received message %s", msg));
+ return "bla";
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.