Package org.nasutekds.server.replication.common

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


     */
    DN baseDn = DN.decode(dn);
    ServerState origState = new ServerState();
    PersistentServerState state =
      new PersistentServerState(baseDn,  1, origState);
    ChangeNumberGenerator gen1 =
      new ChangeNumberGenerator( 1, origState);
    ChangeNumberGenerator gen2 =
      new ChangeNumberGenerator( 2, origState);

    ChangeNumber cn1 = gen1.newChangeNumber();
    ChangeNumber cn2 = gen2.newChangeNumber();

    assertEquals(state.update(cn1), true);
    assertEquals(state.update(cn2), true);

    state.save();
View Full Code Here


      String serviceID1 = "serviceID1";
      String serviceID2 = "serviceID2";
      String serviceID3 = "serviceID3";

      ChangeNumberGenerator gen = new ChangeNumberGenerator( 1, 0);
      ChangeNumber changeNumber1 = gen.newChangeNumber();
      ChangeNumber changeNumber2 = gen.newChangeNumber();
      ChangeNumber changeNumber3 = gen.newChangeNumber();

      // Add records
      handler.add(sn1, value1, serviceID1, changeNumber1);
      handler.add(sn2, value2, serviceID2, changeNumber2);
      handler.add(sn3, value3, serviceID3, changeNumber3);
View Full Code Here

      String serviceID1 = "serviceID1";
      String serviceID2 = "serviceID2";
      String serviceID3 = "serviceID3";

      ChangeNumberGenerator gen = new ChangeNumberGenerator( 1, 0);
      ChangeNumber changeNumber1 = gen.newChangeNumber();
      ChangeNumber changeNumber2 = gen.newChangeNumber();
      ChangeNumber changeNumber3 = gen.newChangeNumber();

      // Add records
      handler.add(sn1, value1, serviceID1, changeNumber1);
      handler.add(sn2, value2, serviceID2, changeNumber2);
      handler.add(sn3, value3, serviceID3, changeNumber3);
View Full Code Here

      /*
       * Create a Change number generator to generate new changenumbers
       * when we need to send operation messages to the replicationServer.
       */
      ChangeNumberGenerator gen = new ChangeNumberGenerator(server3ID, 0);

      for (int i = 0; i < 10; i++)
      {
        broker3.publish(createAddMsg(gen.newChangeNumber(), server3ID));
      }

      searchMonitor();

      debugInfo(
View Full Code Here

    } catch(Exception e) {
      fail("Could not initialize backend : " + e.getMessage());
    }

    // initialize cn generator
    gen = new ChangeNumberGenerator(DS2_ID, 0L);
  }
View Full Code Here

      super("BrokerWriter for broker " + serverId);
      this.rb = rb;
      this.serverId = serverId;
      // Create a Change number generator to generate new change numbers
      // when we need to send changes
      gen = new ChangeNumberGenerator(serverId, 0);

      // Start thread (is paused by default so will have to call follow anyway)
      start();

      // Also create reader ?
View Full Code Here

      Thread.sleep(2000);
      // send a sequence of add operation

      String addDn = TEST_ROOT_DN_STRING;
      ChangeNumberGenerator gen = new ChangeNumberGenerator(brokerId, 0L);

      int sequence;
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        entry.removeAttribute(uidType);
        entry.addAttribute(Attributes.create("entryuuid", stringUID(sequence+1)),
                           new LinkedList<AttributeValue>());
        addDn = "dc=dependency" + sequence + "," + addDn;
        AddMsg addMsg =
          new AddMsg(gen.newChangeNumber(), addDn, stringUID(sequence+1),
                     stringUID(sequence),
                     entry.getObjectClassAttribute(),
                     entry.getAttributes(), null );
        broker.publish(addMsg);

        ModifyMsg modifyMsg =
          new ModifyMsg(gen.newChangeNumber(), DN.decode(addDn),
                        generatemods("description", "test"),
                        stringUID(sequence+1));
        broker.publish(modifyMsg);
      }

      // configure and start replication of TEST_ROOT_DN_STRING on the server
      SortedSet<String> replServers = new TreeSet<String>();
      replServers.add("localhost:"+replServerPort);
      DomainFakeCfg domainConf =
        new DomainFakeCfg(baseDn, serverId, replServers);
      domainConf.setHeartbeatInterval(100000);

      domain = MultimasterReplication.createNewDomain(domainConf);
      domain.start();

      // check that last entry in sequence got added.
      Entry lastEntry = getEntry(DN.decode(addDn), 30000, true);
      assertNotNull(lastEntry,
                    "The last entry of the ADD sequence was not added.");

      // Check that all the modify have been replayed
      // (all the entries should have a description).
      addDn = TEST_ROOT_DN_STRING;
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        addDn = "dc=dependency" + sequence + "," + addDn;

        boolean found =
          checkEntryHasAttribute(DN.decode(addDn), "description", "test",
                                 10000, true);
        if (!found)
        {
          fail("The modification was not replayed on entry " + addDn);
        }
      }

      /*
       * SECOND PART
       *
       * Now check that the dependencies between delete are correctly
       * managed.
       *
       * disable the domain while we publish the delete message to
       * to replication server so that when we enable it it receives the
       * delete operation in bulk.
       */

      domain.disable();
      Thread.sleep(2000)// necesary because disable does not wait
                           // for full termination of all threads. (issue 1571)

      DN deleteDN = DN.decode(addDn);
      while (sequence-->1)
      {
        DeleteMsg delMsg = new DeleteMsg(deleteDN.toString(),
                                         gen.newChangeNumber(),
                                         stringUID(sequence + 1));
        broker.publish(delMsg);
        deleteDN = deleteDN.getParent();
      }

View Full Code Here

      + "objectClass: top\n"
      + "objectClass: organization\n";
      Entry entry = TestCaseUtils.entryFromLdifString(entryldif);
      AttributeType uidType =
        DirectoryServer.getSchema().getAttributeType("entryuuid");
      ChangeNumberGenerator gen = new ChangeNumberGenerator(brokerId, 0L);
      int renamedEntryUuid = 100;

      // find  a free port for the replicationServer
      ServerSocket socket = TestCaseUtils.bindFreePort();
      int replServerPort = socket.getLocalPort();
      socket.close();

      ReplServerFakeConfiguration conf =
        new ReplServerFakeConfiguration(replServerPort, "dependencyTestModdnDelDependencyTestDb",
                                        0, replServerId, 0,
                                        200, null);
      replServer = new ReplicationServer(conf);

      // configure and start replication of TEST_ROOT_DN_STRING on the server
      SortedSet<String> replServers = new TreeSet<String>();
      replServers.add("localhost:"+replServerPort);
      DomainFakeCfg domainConf =
        new DomainFakeCfg(baseDn, serverId, replServers);
      domainConf.setHeartbeatInterval(100000);

      Thread.sleep(2000);
      domain = MultimasterReplication.createNewDomain(domainConf);
      domain.start();

      ReplicationBroker broker =
        openReplicationSession(baseDn, brokerId, 1000, replServerPort, 1000,
                               false, CLEAN_DB_GENERATION_ID);

      // add an entry to play with.
      entry.removeAttribute(uidType);
      entry.addAttribute(Attributes.create("entryuuid",
                         stringUID(renamedEntryUuid)),
                         new LinkedList<AttributeValue>());
      String addDn = "dc=moddndel" + "," + TEST_ROOT_DN_STRING;
      AddMsg addMsg =
        new AddMsg(gen.newChangeNumber(), addDn, stringUID(renamedEntryUuid),
                   stringUID(1),
                   entry.getObjectClassAttribute(),
                   entry.getAttributes(), null );

      broker.publish(addMsg);

      // check that the entry was correctly added
      boolean found =
        checkEntryHasAttribute(DN.decode(addDn), "entryuuid",
                               stringUID(renamedEntryUuid),
                               30000, true);

      assertTrue(found, "The initial entry add failed");


      // disable the domain to make sure that the messages are
      // all sent in a row.
      domain.disable();

      // rename and delete the entry.
      ModifyDNMsg moddnMsg =
        new ModifyDNMsg(addDn, gen.newChangeNumber(),
                        stringUID(renamedEntryUuid),
                        stringUID(1), true, null, "dc=new_name");
      broker.publish(moddnMsg);
      DeleteMsg delMsg =
        new DeleteMsg("dc=new_name" + "," + TEST_ROOT_DN_STRING,
                      gen.newChangeNumber(), stringUID(renamedEntryUuid));
      broker.publish(delMsg);

      // enable back the domain to trigger message replay.
      domain.enable();
View Full Code Here

      ReplicationBroker broker =
        openReplicationSession(baseDn, brokerId, 100, replServerPort, 1000,
                               false, CLEAN_DB_GENERATION_ID);

      // send a sequence of add/del/add operations
      ChangeNumberGenerator gen = new ChangeNumberGenerator(brokerId, 0L);

      int sequence;
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        // add the entry a first time
        entry.removeAttribute(uidType);
        entry.addAttribute(Attributes.create("entryuuid", stringUID(sequence+1)),
                           new LinkedList<AttributeValue>());
        String addDn = "dc=dependency" + sequence + "," + TEST_ROOT_DN_STRING;
        AddMsg addMsg =
          new AddMsg(gen.newChangeNumber(), addDn, stringUID(sequence+1),
                     stringUID(1),
                     entry.getObjectClassAttribute(),
                     entry.getAttributes(), null );
        broker.publish(addMsg);

        // delete the entry
        DeleteMsg delMsg = new DeleteMsg(addDn, gen.newChangeNumber(),
                                         stringUID(sequence+1));
        broker.publish(delMsg);

        // add again the entry with a new entryuuid.
        entry.removeAttribute(uidType);
        entry.addAttribute(Attributes.create("entryuuid", stringUID(sequence+1025)),
                           new LinkedList<AttributeValue>());
        addMsg =
          new AddMsg(gen.newChangeNumber(), addDn, stringUID(sequence+1025),
                     stringUID(1),
                     entry.getObjectClassAttribute(),
                     entry.getAttributes(), null );
        broker.publish(addMsg);
      }

      // configure and start replication of TEST_ROOT_DN_STRING on the server
      SortedSet<String> replServers = new TreeSet<String>();
      replServers.add("localhost:"+replServerPort);
      DomainFakeCfg domainConf =
        new DomainFakeCfg(baseDn, serverId, replServers);

      domain = MultimasterReplication.createNewDomain(domainConf);
      domain.start();

      // check that all entries have been deleted and added
      // again by checking that they do have the correct entryuuid
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        String addDn = "dc=dependency" + sequence + "," + TEST_ROOT_DN_STRING;

        boolean found =
          checkEntryHasAttribute(DN.decode(addDn), "entryuuid",
                                 stringUID(sequence+1025),
                                 30000, true);
        if (!found)
        {
          fail("The second add was not replayed on entry " + addDn);
        }
      }

      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        String deleteDN = "dc=dependency" + sequence + "," + TEST_ROOT_DN_STRING;
        DeleteMsg delMsg = new DeleteMsg(deleteDN,
                                         gen.newChangeNumber(),
                                         stringUID(sequence + 1025));
        broker.publish(delMsg);
      }

      // check that the database was cleaned successfully
View Full Code Here

        openReplicationSession(baseDn, brokerId, 100, replServerPort, 1000,
                               false, CLEAN_DB_GENERATION_ID);


      String addDn = TEST_ROOT_DN_STRING;
      ChangeNumberGenerator gen = new ChangeNumberGenerator(brokerId, 0L);

      // send a sequence of add/modrdn operations
      int sequence;
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        // add the entry
        entry.removeAttribute(uidType);
        entry.addAttribute(Attributes.create("entryuuid", stringUID(sequence+1)),
                           new LinkedList<AttributeValue>());
        addDn = "dc=dependency" + sequence + "," + TEST_ROOT_DN_STRING;
        AddMsg addMsg =
          new AddMsg(gen.newChangeNumber(), addDn, stringUID(sequence+1),
                     stringUID(1),
                     entry.getObjectClassAttribute(),
                     entry.getAttributes(), null );
        broker.publish(addMsg);

        // rename the entry
        ModifyDNMsg moddnMsg =
          new ModifyDNMsg(addDn, gen.newChangeNumber(), stringUID(sequence+1),
                          stringUID(1), true, null, "dc=new_dep" + sequence);
        broker.publish(moddnMsg);
      }

      // configure and start replication of TEST_ROOT_DN_STRING on the server
      SortedSet<String> replServers = new TreeSet<String>();
      replServers.add("localhost:"+replServerPort);
      DomainFakeCfg domainConf =
        new DomainFakeCfg(baseDn, serverId, replServers);

      domain = MultimasterReplication.createNewDomain(domainConf);
      domain.start();

      // check that all entries have been renamed
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        addDn = "dc=new_dep" + sequence + "," + TEST_ROOT_DN_STRING;

        Entry baseEntry = getEntry(DN.decode(addDn), 30000, true);
        assertNotNull(baseEntry,
          "The rename was not applied correctly on :" + addDn);
      }

      // delete the entries to clean the database.
      for (sequence = 1; sequence<=AddSequenceLength; sequence ++)
      {
        addDn = "dc=new_dep" + sequence + "," + TEST_ROOT_DN_STRING;
        DeleteMsg delMsg = new DeleteMsg(addDn.toString(),
                                         gen.newChangeNumber(),
                                         stringUID(sequence + 1));
        broker.publish(delMsg);
      }
    }
    finally
View Full Code Here

TOP

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

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.