Package org.nasutekds.server.replication.common

Examples of org.nasutekds.server.replication.common.ChangeNumber


    LinkedList<ReplicationMsg> opList = new LinkedList<ReplicationMsg>();
    TestBroker session = new TestBroker(opList);

    boolean result =
      rd1.buildAndPublishMissingChanges(
          new ChangeNumber(startTime, 0, serverId),
          session);
    assertTrue(result, "buildAndPublishMissingChanges has failed");
    assertEquals(opList.size(), 3, "buildAndPublishMissingChanges should return 3 operations");
    assertTrue(opList.getFirst().getClass().equals(AddMsg.class));


    // Build a change number from the first modification
    String hv[] = histValue.split(":");
    logError(Message.raw(Category.SYNC, Severity.INFORMATION, hv[1]));
    ChangeNumber fromChangeNumber = new ChangeNumber(hv[1]);

    opList = new LinkedList<ReplicationMsg>();
    session = new TestBroker(opList);

    result =
View Full Code Here


    // Call the buildAndPublishMissingChanges and check that this method
    // correctly generates the 4 operations in the correct order.
    boolean result =
      rd1.buildAndPublishMissingChanges(
          new ChangeNumber(startTime, 0, serverId),
          session);
    assertTrue(result, "buildAndPublishMissingChanges has failed");
    assertEquals(opList.size(), 5, "buildAndPublishMissingChanges should return 5 operations");
    ReplicationMsg msg = opList.removeFirst();
    assertTrue(msg.getClass().equals(AddMsg.class));
View Full Code Here

    AttributeValue att1 = AttributeValues.create(type, "string");
    AttributeValue att2 = AttributeValues.create(type, "value");
    AttributeValue att3 = AttributeValues.create(type, "again");

    ChangeNumber del1 = new ChangeNumber(101);
    ChangeNumber del2 = new ChangeNumber(111);
    ChangeNumber del3 = new ChangeNumber(102);

    ChangeNumber upd1 = new ChangeNumber(TimeThread.getTime(), 123, 45);
    ChangeNumber upd2 = new ChangeNumber(TimeThread.getTime()+ 1000, 123, 45);
    ChangeNumber upd3 = new ChangeNumber(TimeThread.getTime(), 321, 54);

    return new Object[][] {
        {att1,null,null},
        {att1,upd1,del1},
        {att2,upd2,del2},
View Full Code Here

   */
  @Test(dataProvider = "changeNumberData")
  public void CreateChangeNumber(long time, int seq, int id, String str)
         throws Exception
  {
    ChangeNumber cn = new ChangeNumber(time,seq,id);
    assertEquals(cn.toString(), str);

    new ChangeNumber(time,seq,id);
    new ChangeNumber(time+1,seq,id) ;
    new ChangeNumber(time,seq+1,id) ;
    new ChangeNumber(time,seq,id+1);
  }
View Full Code Here

@Test(dataProvider = "changeNumberData")
public void ChangeNumberEncodeDecode(long time, int seq, int id, String str)
        throws Exception
{
   // Create 2 ChangeNumber with the same data and check equality
   ChangeNumber cn = new ChangeNumber(time,seq,id);
   ChangeNumber cn2 = new ChangeNumber(cn.toString());

   assertEquals(cn, cn2,
       "The encoding/decoding of ChangeNumber is not reversible");
   assertEquals(cn2.toString(), str,
       "The encoding/decoding of ChangeNumber is not reversible for toString()");
}
View Full Code Here

    int id [] = {145} ;

    Object[][] obj = new Object[time.length][5];
    for (int i=0; i<time.length; i++)
    {
      obj[i][0] = new ChangeNumber(time[i],seq[i],id[i]);
      obj[i][1] = new ChangeNumber(time[i],seq[i],id[i]);
      obj[i][2] = new ChangeNumber(time[i]+1,seq[i],id[i]);
      obj[i][3] = new ChangeNumber(time[i],seq[i]+1,id[i]);
      obj[i][4] = new ChangeNumber(time[i],seq[i],id[i]+1);
    }
    return obj;
  }
View Full Code Here

   */
  @Test
  public void changeNumberGenerator()
         throws Exception
  {
    ChangeNumber CN1;
    ChangeNumber CN2;

    // Generated the ChangeNumberGenerator object
    ChangeNumberGenerator cng =
      new ChangeNumberGenerator( 0, TimeThread.getTime());

    // Generate 2 changeNumbers and check that they are differents
    CN1 = cng.newChangeNumber();
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0);

    // Generate a changeNumber separates by 10 milliseconds
    // and check that they are differents
    Thread.sleep(10);
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0);

    // Generate a changeNumber separates by 300 milliseconds
    // and check that they are differents
    Thread.sleep(300);
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0);

    // Adjust with the oldest CN
    cng.adjust(CN1) ;
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0 );

    // Adjust with the newest generated
    cng.adjust(CN2) ;
    CN1 = CN2;
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0 );

    //  Adjust with the newest generated (time + 300)
    CN1 = new ChangeNumber(CN2.getTime() +300 ,CN2.getSeqnum(),
        CN2.getServerId()) ;
    cng.adjust(CN1) ;
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0 );

    //  Adjust with the newest generated (seqmun + 10)
    CN1 = new ChangeNumber(CN2.getTime() ,CN2.getSeqnum() +10,
        CN2.getServerId()) ;
    cng.adjust(CN1) ;
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0 );

    //  Adjust with the newest generated (seqmun = 0XFFFF)
    CN1 = new ChangeNumber(CN2.getTime() ,0XFFFF +10,CN2.getServerId()) ;
    cng.adjust(CN1) ;
    CN2 = cng.newChangeNumber();
    assertTrue(CN1.compareTo(CN2) != 0 );
  }
View Full Code Here

   */
  @Test
  public void changeNumberDiffSeqNum()
         throws Exception
  {
    ChangeNumber CN1;
    ChangeNumber CN2;

    CN1 = new ChangeNumber((long)0, 3, 0);

    // 3-0 = 3
    CN2 = new ChangeNumber((long)0, 0, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 3);

    // 3-1 = 2
    CN2 = new ChangeNumber((long)0, 1, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 2);

    // 3-3 = 0
    CN2 = new ChangeNumber((long)0, 3, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 0);

    // 3-4 = 0 (CN1 must be newer otherwise 0 should be returned)
    CN2 = new ChangeNumber((long)0, 4, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 0);

    CN1 = new ChangeNumber((long)0, 0, 0);

    // 0-0 = 0
    CN2 = new ChangeNumber((long)0, 0, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 0);

    // 0-1 = 0 (CN1 must be newer otherwise 0 should be returned)
    CN2 = new ChangeNumber((long)0, 1, 0);
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 0);

    CN1 = new ChangeNumber((long)0, 5, 0);
    CN2 = new ChangeNumber((long)0, 2, 0);

    // 5-null = 5
    assertEquals(ChangeNumber.diffSeqNum(CN1, null), 5);

    // null-2 = 0
    assertEquals(ChangeNumber.diffSeqNum(null, CN2), 0);

    // null-null = 0
    assertEquals(ChangeNumber.diffSeqNum(null, null), 0);

    CN1 = new ChangeNumber((long)1111111, 2, 0);
    CN2 = new ChangeNumber((long)3333333, 4, 0);

    // CN1 older than CN2 -> 0
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 0);

    CN1 = new ChangeNumber((long)3333333, 1, 0);
    CN2 = new ChangeNumber((long)1111111, Integer.MAX_VALUE-1, 0);

    // CN1 seqnum looped
    assertEquals(ChangeNumber.diffSeqNum(CN1, CN2), 3);
  }
View Full Code Here

   * Create ChangeNumber Data
   */
  @DataProvider(name = "changeNumberData")
  public Object[][] createChangeNumberData() {
    return new Object[][] {
       {new ChangeNumber(1, 0, 1)},
       {new ChangeNumber(TimeThread.getTime()12345)}
    };
  }
View Full Code Here

    // Check update
    assertFalse(serverState.update((ChangeNumber)null));
    assertTrue(serverState.update(cn));
    assertFalse(serverState.update(cn));
    ChangeNumber cn1, cn2, cn3;
    cn1 = new ChangeNumber(cn.getTime()+1,cn.getSeqnum(),cn.getServerId());
    cn2 = new ChangeNumber(cn1.getTime(),cn1.getSeqnum()+1,cn1.getServerId());
    cn3 = new ChangeNumber(cn2.getTime(),cn2.getSeqnum(),(cn2.getServerId()+1));

    assertTrue(serverState.update(cn1)) ;
    assertTrue(serverState.update(cn2)) ;
    assertTrue(serverState.update(cn3)) ;
View Full Code Here

TOP

Related Classes of org.nasutekds.server.replication.common.ChangeNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.