Package org.nasutekds.server.replication.service

Examples of org.nasutekds.server.replication.service.ReplicationBroker


    /*
     * Open a session to the replicationServer using the broker API.
     * This must use a different serverId to that of the directory server.
     */
    ReplicationBroker broker =
      openReplicationSession(baseDn, 2, 100, replServerPort, 1000, true);


    // Clear the backend and create top entrye
    TestCaseUtils.initializeTestBackend(true);
View Full Code Here


   * before failing.
   */
  private void checkConnection(int secTimeout, int dsId)
  {

    ReplicationBroker rb = null;
    LDAPReplicationDomain rd = null;
    switch (dsId)
    {
      case DS1_ID:
        rd = ds1;
        break;
      case DS2_ID:
        rb = ds2;
        break;
      case DS3_ID:
        rb = ds3;
        break;
      default:
        fail("Unknown ds server id.");
    }

    int nSec = 0;

    // Go out of the loop only if connection is verified or if timeout occurs
    while (true)
    {
      // Test connection
      boolean connected = false;
      if (rd != null)
        connected = rd.isConnected();
      else
        connected = rb.isConnected();

      if (connected)
      {
        // Connection verified
        debugInfo("checkConnection: connection of DS " + dsId +
View Full Code Here

   */
  private ReplicationBroker createReplicationBroker(int dsId,
    ServerState state, long generationId, int window)
    throws Exception, SocketException
  {
    ReplicationBroker broker = new ReplicationBroker(null,
      state, EXAMPLE_DN, dsId, 100, generationId, 0,
      new ReplSessionSecurity(null, null, null, true), (byte) 1, 500);
    ArrayList<String> servers = new ArrayList<String>(1);
    servers.add("localhost:" + rs1Port);
    broker.start(servers);
    checkConnection(30, broker, rs1Port);

    return broker;
  }
View Full Code Here

        new ReplServerFakeConfiguration(replServerPort, "dependencyTestAddModDelDependencyTestDb",
                                        0, replServerId, 0,
                                        AddSequenceLength*5+100, null);
      replServer = new ReplicationServer(conf);

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

      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();
      }

      domain.enable();

View Full Code Here

      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();

      // check that entry does not exist anymore.
View Full Code Here

        new ReplServerFakeConfiguration(replServerPort, "dependencyTestAddDelAddDependencyTestDb", 0,
                                        replServerId,
                                        0, 5*AddSequenceLength+100, null);
      replServer = new ReplicationServer(conf);

      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
      DN node1 = DN.decode("dc=dependency1," + TEST_ROOT_DN_STRING);
      Entry baseEntry = getEntry(node1, 30000, false);
View Full Code Here

        new ReplServerFakeConfiguration(replServerPort, "dependencyTestAddModdnDependencyTestDb", 0,
                                        replServerId,
                                        0, 5*AddSequenceLength+100, null);
      replServer = new ReplicationServer(conf);

      ReplicationBroker broker =
        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
    {
      if (replServer != null)
View Full Code Here

    TestCaseUtils.initializeTestBackend(false);

    replServer1 = createReplicationServer(changelog1ID, false, testCase);
    replServer1.clearDb();

    ReplicationBroker broker = null;
    try
    {
      for (int i=0; i< 5; i++)
      {
        long generationId = 1000+i;
        broker = openReplicationSession(baseDn,
            server2ID, 100, getChangelogPort(changelog1ID),
            1000, !emptyOldChanges, generationId);
        debugInfo(testCase + " Expect genId to be set in memory on the replication " +
          " server side even if not wrote on disk/db since no change occurred.");
        rgenId = replServer1.getGenerationId(baseDn.toNormalizedString());
        assertEquals(rgenId, generationId);
        broker.stop();
        broker = null;
        Thread.sleep(2000); // Let time to RS to clear info about previous connection
      }
    } finally
    {
      if (broker != null)
        broker.stop();
      postTest();
    }
  }
View Full Code Here

    cleanUpReplicationServersDB();

    final DN baseDn = DN.decode("cn=schema");

    ReplicationBroker broker =
      openReplicationSession(baseDn,  2, 100, replServerPort, 5000, true);

    try
    {
      // Modify the schema
      Attribute attr = Attributes.create("attributetypes",
          "( 2.5.44.77.33 NAME 'dummy' )");
      List<Modification> mods = new ArrayList<Modification>();
      Modification mod = new Modification(ModificationType.ADD, attr);
      mods.add(mod);
      ModifyOperationBasis modOp = new ModifyOperationBasis(connection,
          InternalClientConnection.nextOperationID(), InternalClientConnection
          .nextMessageID(), null, baseDn, mods);
      modOp.setInternalOperation(true);
      modOp.run();

      ResultCode code = modOp.getResultCode();
      assertTrue(code.equals(ResultCode.SUCCESS),
                 "The original operation failed: " + code.getResultCodeName());

      // See if the client has received the msg
      ReplicationMsg msg = broker.receive();

      assertTrue(msg instanceof ModifyMsg,
                 "The received replication message is not a MODIFY msg");
      ModifyMsg modMsg = (ModifyMsg) msg;

      Operation receivedOp = modMsg.createOperation(connection);
      assertTrue(DN.decode(modMsg.getDn()).compareTo(baseDn) == 0,
                 "The received message is not for cn=schema");

      assertTrue(receivedOp instanceof ModifyOperation,
                 "The received replication message is not a MODIFY msg");
      ModifyOperation receivedModifyOperation = (ModifyOperation) receivedOp;

      List<RawModification> rcvdRawMods =
        receivedModifyOperation.getRawModifications();

      this.rcvdMods = new ArrayList<Modification>();
      for (RawModification m : rcvdRawMods)
      {
        this.rcvdMods.add(m.toModification());
      }

      assertTrue(this.rcvdMods.contains(mod),
                 "The received mod does not contain the original change");

      /*
       * Now cleanup the schema for the next test
       */
      mod = new Modification(ModificationType.DELETE, attr);
      mods.clear();
      mods.add(mod);
      modOp = new ModifyOperationBasis(connection,
          InternalClientConnection.nextOperationID(), InternalClientConnection
          .nextMessageID(), null, baseDn, mods);
      modOp.setInternalOperation(true);
      modOp.run();

      code = modOp.getResultCode();
      assertTrue(code.equals(ResultCode.SUCCESS),
                 "The original operation failed" + code.getResultCodeName());

      // See if the client has received the msg
      msg = broker.receive();

      assertTrue(msg instanceof ModifyMsg,
                 "The received replication message is not a MODIFY msg");
    }
    finally
    {
      broker.stop();
    }
  }
View Full Code Here

    cleanUpReplicationServersDB();

    final DN baseDn = DN.decode("cn=schema");

    ReplicationBroker broker =
      openReplicationSession(baseDn,  2, 100, replServerPort, 5000, true);

    try
    {
      ChangeNumberGenerator gen = new ChangeNumberGenerator( 2, 0);

      ModifyMsg modMsg = new ModifyMsg(gen.newChangeNumber(),
        baseDn, rcvdMods, "cn=schema");
      broker.publish(modMsg);

      boolean found = checkEntryHasAttribute(baseDn, "attributetypes",
        "( 2.5.44.77.33 NAME 'dummy' )",
        10000, true);

      if (found == false)
        fail("The modification has not been correctly replayed.");
    }
    finally
    {
      broker.stop();
    }
  }
View Full Code Here

TOP

Related Classes of org.nasutekds.server.replication.service.ReplicationBroker

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.