mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

gbellato
24.04.2009 9eb54b5b0e109ecbaee9aa109b32dbf42323bd55
opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java
@@ -418,7 +418,7 @@
    heartbeatInterval = serverStartMsg.getHeartbeatInterval();
    // generic stuff
    setServiceIdAndDomain(serverStartMsg.getBaseDn());
    setServiceIdAndDomain(serverStartMsg.getBaseDn(), true);
    setInitialServerState(serverStartMsg.getServerState());
    setSendWindowSize(serverStartMsg.getWindowSize());
@@ -474,8 +474,6 @@
      boolean sessionInitiatorSSLEncryption =
        processStartFromRemote(inServerStartMsg);
      // Get or Create the ReplicationServerDomain
      replicationServerDomain = getDomain(true, true);
      localGenerationId = replicationServerDomain.getGenerationId();
      oldGenerationId = localGenerationId;
opendj-sdk/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
@@ -351,7 +351,7 @@
        replicationServer, rcvWindowSize);
    try
    {
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT);
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
    }
    catch(DirectoryException de)
    {
@@ -381,7 +381,7 @@
        replicationServer, 0);
    try
    {
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT);
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
    }
    catch(DirectoryException de)
    {
@@ -673,7 +673,7 @@
          // set initial state
          mh.setInitialServerState(newDomainCtxt.startState);
          // set serviceID and domain
          mh.setServiceIdAndDomain(rsd.getBaseDn());
          mh.setServiceIdAndDomain(rsd.getBaseDn(), false);
          // register the unconnected into the domain
          rsd.registerHandler(mh);
          newDomainCtxt.mh = mh;
opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java
@@ -717,10 +717,13 @@
  /**
   * Set the serviceId (usually baseDn) for this handler. Expected to be done
   * once and never changed during the handler life.
   * @param serviceId The provided serviceId.
   *
   * @param serviceId       The provided serviceId.
   * @param isDataServer    The handler is a dataServer
   *
   * @exception DirectoryException raised when a problem occurs.
   */
  protected void setServiceIdAndDomain(String serviceId)
  protected void setServiceIdAndDomain(String serviceId, boolean isDataServer)
  throws DirectoryException
  {
    if (this.serviceId != null)
@@ -737,7 +740,7 @@
    else
    {
      this.serviceId = serviceId;
      this.replicationServerDomain = getDomain(true);
      this.replicationServerDomain = getDomain(true, isDataServer);
    }
  }
opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -1501,7 +1501,7 @@
      } else
      {
        // the targeted server is NOT connected
        // Let's search for THE changelog server that MAY
        // Let's search for the replication server that MAY
        // have the targeted server connected.
        if (senderHandler.isDataServer())
        {
opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -93,7 +93,7 @@
      serverAddressURL =
        session.getRemoteAddress() + ":" + serverURL.substring(separator +
            1);
      setServiceIdAndDomain(inReplServerStartMsg.getBaseDn());
      setServiceIdAndDomain(inReplServerStartMsg.getBaseDn(), false);
      setInitialServerState(inReplServerStartMsg.getServerState());
      setSendWindowSize(inReplServerStartMsg.getWindowSize());
      if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
@@ -156,7 +156,7 @@
    // the encryption we will request to the peer as we are the session creator
    this.initSslEncryption = sslEncryption;
    setServiceIdAndDomain(serviceId);
    setServiceIdAndDomain(serviceId, false);
    localGenerationId = replicationServerDomain.getGenerationId();
    oldGenerationId = localGenerationId;
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java
@@ -279,8 +279,10 @@
        replServer1.remove();
    }
  }
  /**
   * Test that a ReplicationDomain is able to export and import its database.
   * Test that a ReplicationDomain is able to export and import its database
   * When there is only one replication server.
   */
  @Test(enabled=true)
  public void exportAndImport() throws Exception
@@ -363,6 +365,104 @@
  }
  /**
   * Test that a ReplicationDomain is able to export and import its database
   * across 2 replication servers.
   */
  @Test(enabled=true)
  public void exportAndImportAcross2ReplServers() throws Exception
  {
    final int ENTRYCOUNT=5000;
    String testService = "test";
    ReplicationServer replServer2 = null;
    ReplicationServer replServer1 = null;
    int replServerID = 11;
    int replServerID2 = 12;
    FakeReplicationDomain domain1 = null;
    FakeReplicationDomain domain2 = null;
    try
    {
      // find  a free port for the replicationServer
      ServerSocket socket = TestCaseUtils.bindFreePort();
      int replServerPort1 = socket.getLocalPort();
      socket.close();
      socket = TestCaseUtils.bindFreePort();
      int replServerPort2 = socket.getLocalPort();
      socket.close();
      TreeSet<String> replserver1 = new TreeSet<String>();
      replserver1.add("localhost:" + replServerPort1);
      TreeSet<String> replserver2 = new TreeSet<String>();
      replserver2.add("localhost:" + replServerPort2);
      ReplServerFakeConfiguration conf1 =
        new ReplServerFakeConfiguration(
            replServerPort1, "ReplicationDomainTestDb",
            0, replServerID, 0, 100, null);
      ReplServerFakeConfiguration conf2 =
        new ReplServerFakeConfiguration(
            replServerPort2, "ReplicationDomainTestDb",
            0, replServerID2, 0, 100, replserver1);
      replServer1 = new ReplicationServer(conf1);
      replServer2 = new ReplicationServer(conf2);
      ArrayList<String> servers1 = new ArrayList<String>(1);
      servers1.add("localhost:" + replServerPort1);
      ArrayList<String> servers2 = new ArrayList<String>(1);
      servers2.add("localhost:" + replServerPort2);
      StringBuilder exportedDataBuilder = new StringBuilder();
      for (int i =0; i<ENTRYCOUNT; i++)
      {
        exportedDataBuilder.append("key : value"+i+"\n\n");
      }
      String exportedData=exportedDataBuilder.toString();
      domain1 = new FakeReplicationDomain(
          testService, (short) 1, servers1,
          100, 0, exportedData, null, ENTRYCOUNT);
      StringBuilder importedData = new StringBuilder();
      domain2 = new FakeReplicationDomain(
          testService, (short) 2, servers2, 100, 0,
          null, importedData, 0);
      domain2.initializeFromRemote((short)1);
      int count = 0;
      while ((importedData.length() < exportedData.length()) && (count < 500))
      {
        count ++;
        Thread.sleep(100);
      }
      assertTrue(domain2.getLeftEntryCount() == 0,
          "LeftEntryCount for export is " + domain2.getLeftEntryCount());
      assertTrue(domain1.getLeftEntryCount() == 0,
          "LeftEntryCount for import is " + domain1.getLeftEntryCount());
      assertEquals(importedData.length(), exportedData.length());
      assertEquals(importedData.toString(), exportedData);
    }
    finally
    {
      if (domain1 != null)
        domain1.disableService();
      if (domain2 != null)
        domain2.disableService();
      if (replServer1 != null)
        replServer1.remove();
      if (replServer2 != null)
        replServer2.remove();
    }
  }
  /**
   * Sender side of the Total Update Perf test.
   * The goal of this test is to measure the performance
   * of the total update code.