Beispiel #1
0
  public void testMergeWithAsymetricViewsCoordIsolated() {
    // Isolate the coord
    Address coord = a.getView().getCreator();
    System.out.println("Isolating coord: " + coord);
    List<Address> members = new ArrayList<>();
    members.add(coord);
    View coord_view = new View(coord, 4, members);
    System.out.println("coord_view: " + coord_view);
    Channel coord_channel = findChannel(coord);
    System.out.println("coord_channel: " + coord_channel.getAddress());

    MutableDigest digest = new MutableDigest(coord_view.getMembersRaw());
    NAKACK2 nakack = (NAKACK2) coord_channel.getProtocolStack().findProtocol(NAKACK2.class);
    digest.merge(nakack.getDigest(coord));

    GMS gms = (GMS) coord_channel.getProtocolStack().findProtocol(GMS.class);
    gms.installView(coord_view, digest);
    System.out.println("gms.getView() " + gms.getView());

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getAddress() + ": " + ch.getView());

    JChannel merge_leader = findChannel(coord);
    MyReceiver receiver = new MyReceiver();
    merge_leader.setReceiver(receiver);

    System.out.println("merge_leader: " + merge_leader.getAddressAsString());

    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(4);
    merge_views.put(a.getAddress(), a.getView());
    merge_views.put(b.getAddress(), b.getView());
    merge_views.put(c.getAddress(), c.getView());
    merge_views.put(d.getAddress(), d.getView());

    gms = (GMS) merge_leader.getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, merge_views));

    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b, c, d);

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      View view = ch.getView();
      System.out.println(ch.getAddress() + ": " + view);
      assert view.size() == 4;
    }
    MergeView merge_view = receiver.getView();
    System.out.println("merge_view = " + merge_view);
    assert merge_view.size() == 4;
    assert merge_view.getSubgroups().size() == 2;

    for (View view : merge_view.getSubgroups())
      assert contains(view, a.getAddress())
          || contains(view, b.getAddress(), c.getAddress(), d.getAddress());
  }
  @BeforeMethod
  protected void setup() throws Exception {
    receiver = new MockProtocol();
    nak = (NAKACK2) new NAKACK2().setValue("use_mcast_xmit", false);
    transport = new MockTransport();
    ProtocolStack stack = new ProtocolStack();
    stack.addProtocols(transport, nak, receiver);
    stack.init();

    nak.down(new Event(Event.BECOME_SERVER));
    nak.down(new Event(Event.SET_LOCAL_ADDRESS, A));
    Digest digest = new Digest(view.getMembersRaw(), new long[] {0, 0, 0, 0});
    nak.down(new Event(Event.SET_DIGEST, digest));
  }
  public void testSetDigest() throws TimeoutException {
    System.out.println("d1: " + d1);
    System.out.println("d2: " + d2);

    System.out.println("setting d2:");
    nak.down(new Event(Event.SET_DIGEST, d2));
    Digest digest = (Digest) nak.down(new Event(Event.GET_DIGEST));
    System.out.println("digest = " + digest);
    assert digest.capacity() == 3;
    assert digest.containsAll(a, b, c);

    System.out.println("setting d1:");
    nak.down(new Event(Event.SET_DIGEST, d1));
    digest = (Digest) nak.down(new Event(Event.GET_DIGEST));
    System.out.println("digest = " + digest);
    assert digest.capacity() == 3; // https://jira.jboss.org/jira/browse/JGRP-1060
    assert digest.containsAll(a, b, c);
  }
  @BeforeMethod
  protected void setUp() throws Exception {
    a = Util.createRandomAddress("A");
    b = Util.createRandomAddress("B");
    c = Util.createRandomAddress("C");
    v1 = View.create(a, 1, a, b);
    v2 = View.create(a, 2, a, b, c);

    nak = new NAKACK2();
    d1 = new Digest(v1.getMembersRaw(), new long[] {11, 11, 30, 35});
    d2 = new Digest(v2.getMembersRaw(), new long[] {10, 10, 30, 30, 50, 50});

    TP transport =
        new TP() {
          public boolean supportsMulticasting() {
            return false;
          }

          public void sendMulticast(byte[] data, int offset, int length) throws Exception {}

          public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length)
              throws Exception {}

          public String getInfo() {
            return null;
          }

          public Object down(Event evt) {
            return null;
          }

          protected PhysicalAddress getPhysicalAddress() {
            return null;
          }

          public TimeScheduler getTimer() {
            return new DefaultTimeScheduler(1);
          }
        };
    transport.setId(TP_ID);
    nak.setDownProtocol(transport);
    nak.start();
  }
  /**
   * - Send a few messages such that missing messages are 5,7, 9-13, 18 - Kick off the
   * retransmission task: no retransmit messages must be seen - Send some missing messages and
   * create a few more gaps, such that the missing messages are 5, 10-12, 20-22, 25, 30 - Trigger a
   * retransmit task run - The retransmit requests need to be: 5, 10-12 - Trigger a next run of the
   * retransmit task. The retransmit messages need to be 5, 10-12, 20-22, 25, 30 - Make NAKACK2
   * receive missing messages 5, 10-12 - Kick off another retransmission run: the missing messages
   * are 20-22, 25, 30
   *
   * <p>- Receive all missing messages - On the last run of the retransmit task, no messages are
   * retransmitted
   */
  public void testRetransmission() {
    injectMessages(1, 2, 3, 4, 6, 8, 14, 15, 16, 17, 19);
    assertReceived(1, 2, 3, 4); // only messages 1-4 are delivered, there's a gap at 5

    nak.triggerXmit();
    // assertXmitRequests(5, 7,  9,10,11,12,13,   18);
    assertXmitRequests(); // the first time, there will *not* be any retransmit requests !

    injectMessages(7, 9, 13, 18, 23, 24, 26, 27, 28, 29, 31);
    nak.triggerXmit();
    assertXmitRequests(5, 10, 11, 12);

    nak.triggerXmit();
    assertXmitRequests(5, 10, 11, 12, 20, 21, 22, 25, 30);

    injectMessages(5, 10, 11, 12);
    nak.triggerXmit();
    assertXmitRequests(20, 21, 22, 25, 30);

    injectMessages(20, 21, 22, 25, 30);
    nak.triggerXmit();
    assertXmitRequests();
  }
 /** Makes NAKACK2 receive a message with the given seqno */
 protected void injectMessage(long seqno) {
   Message msg = new Message(null, B, null);
   NakAckHeader2 hdr = NakAckHeader2.createMessageHeader(seqno);
   msg.putHeader(ID, hdr);
   nak.up(new Event(Event.MSG, msg));
 }
 @AfterMethod
 protected void tearDown() {
   nak.stop();
 }