Search in sources :

Example 1 with ObjectPair

use of com.unboundid.util.ObjectPair in project ldapsdk by pingidentity.

the class FewestConnectionsServerSet method handleConnectionClosed.

/**
 * {@inheritDoc}
 */
@Override()
protected void handleConnectionClosed(@NotNull final LDAPConnection connection, @NotNull final String host, final int port, @NotNull final DisconnectType disconnectType, @Nullable final String message, @Nullable final Throwable cause) {
    final ObjectPair<String, Integer> hostPort = new ObjectPair<>(host, port);
    final AtomicLong counter = connectionCountsByServer.get(hostPort);
    if (counter != null) {
        final long remainingCount = counter.decrementAndGet();
        if (remainingCount < 0L) {
            // This shouldn't happen.  If it does, reset it back to zero.
            counter.compareAndSet(remainingCount, 0L);
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ObjectPair(com.unboundid.util.ObjectPair)

Example 2 with ObjectPair

use of com.unboundid.util.ObjectPair in project ldapsdk by pingidentity.

the class MultiUpdateExtendedResult method toString.

/**
 * Appends a string representation of this extended result to the provided
 * buffer.
 *
 * @param  buffer  The buffer to which a string representation of this
 *                 extended result will be appended.
 */
@Override()
public void toString(@NotNull final StringBuilder buffer) {
    buffer.append("MultiUpdateExtendedResult(resultCode=");
    buffer.append(getResultCode());
    final int messageID = getMessageID();
    if (messageID >= 0) {
        buffer.append(", messageID=");
        buffer.append(messageID);
    }
    buffer.append(", changesApplied=");
    buffer.append(changesApplied.name());
    buffer.append(", results={");
    final Iterator<ObjectPair<OperationType, LDAPResult>> resultIterator = results.iterator();
    while (resultIterator.hasNext()) {
        resultIterator.next().getSecond().toString(buffer);
        if (resultIterator.hasNext()) {
            buffer.append(", ");
        }
    }
    final String diagnosticMessage = getDiagnosticMessage();
    if (diagnosticMessage != null) {
        buffer.append(", diagnosticMessage='");
        buffer.append(diagnosticMessage);
        buffer.append('\'');
    }
    final String matchedDN = getMatchedDN();
    if (matchedDN != null) {
        buffer.append(", matchedDN='");
        buffer.append(matchedDN);
        buffer.append('\'');
    }
    final String[] referralURLs = getReferralURLs();
    if (referralURLs.length > 0) {
        buffer.append(", referralURLs={");
        for (int i = 0; i < referralURLs.length; i++) {
            if (i > 0) {
                buffer.append(", ");
            }
            buffer.append('\'');
            buffer.append(referralURLs[i]);
            buffer.append('\'');
        }
        buffer.append('}');
    }
    final Control[] responseControls = getResponseControls();
    if (responseControls.length > 0) {
        buffer.append(", responseControls={");
        for (int i = 0; i < responseControls.length; i++) {
            if (i > 0) {
                buffer.append(", ");
            }
            buffer.append(responseControls[i]);
        }
        buffer.append('}');
    }
    buffer.append(')');
}
Also used : Control(com.unboundid.ldap.sdk.Control) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ObjectPair(com.unboundid.util.ObjectPair)

Example 3 with ObjectPair

use of com.unboundid.util.ObjectPair in project ldapsdk by pingidentity.

the class ServerSetBlacklistManagerTestCase method testMinimalSettings.

/**
 * Tests the blacklist manager with minimal settings.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMinimalSettings() throws Exception {
    // Create a pair of in-memory directory server instances to use for testing.
    final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    final InMemoryDirectoryServer ds1 = new InMemoryDirectoryServer(cfg);
    ds1.startListening();
    final InMemoryDirectoryServer ds2 = new InMemoryDirectoryServer(cfg);
    ds2.startListening();
    // Create a server set and a blacklist manager.
    final String host = "localhost";
    final int port1 = ds1.getListenPort();
    final int port2 = ds2.getListenPort();
    final RoundRobinServerSet serverSet = new RoundRobinServerSet(new String[] { host, host }, new int[] { port1, port2 });
    final ServerSetBlacklistManager blacklistManager = new ServerSetBlacklistManager(serverSet, null, null, null, null, 1L);
    // Validate the blacklist when it should be empty.
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the first directory server instance and add it to the blacklist.
    ds1.shutDown(true);
    blacklistManager.addToBlacklist(host, port1, null);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the second directory server instance and add it to the blacklist.
    ds2.shutDown(true);
    blacklistManager.addToBlacklist(new ObjectPair<>(host, port2), null);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Sleep for at least 10 milliseconds to ensure that the blacklist manager
    // has had plenty of time to fail to re-establish a connection to the
    // blacklisted servers.
    Thread.sleep(10L);
    // Start the first directory server instance and wait for it to be removed
    // from the blacklist.
    ds1.startListening();
    long stopWaitingTime = System.currentTimeMillis() + 60_000L;
    while (System.currentTimeMillis() < stopWaitingTime) {
        if (blacklistManager.isBlacklisted(host, port1)) {
            Thread.sleep(1L);
        } else {
            break;
        }
    }
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Start the second directory server instance and wait for it to be removed
    // from the blacklist.
    ds2.startListening();
    stopWaitingTime = System.currentTimeMillis() + 60_000L;
    while (System.currentTimeMillis() < stopWaitingTime) {
        if (blacklistManager.isBlacklisted(host, port2)) {
            Thread.sleep(1L);
        } else {
            break;
        }
    }
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 0);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the instances again and re-add them to the blacklist.
    ds1.shutDown(true);
    ds2.shutDown(true);
    blacklistManager.addToBlacklist(new ObjectPair<>(host, port1), null);
    blacklistManager.addToBlacklist(host, port2, null);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Sleep for at least 10 milliseconds.
    Thread.sleep(10L);
    // With the Directory Server instances still down, manually remove the first
    // server from the blacklist.
    blacklistManager.removeFromBlacklist(host, port1);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Manually remove the second server from the blacklist.
    blacklistManager.removeFromBlacklist(new ObjectPair<>(host, port2));
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Re-add both servers to the blacklist.
    blacklistManager.addToBlacklist(host, port1, null);
    blacklistManager.addToBlacklist(host, port2, null);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Clear the blacklist.
    blacklistManager.clear();
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    blacklistManager.shutDown();
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) ObjectPair(com.unboundid.util.ObjectPair) Test(org.testng.annotations.Test)

Example 4 with ObjectPair

use of com.unboundid.util.ObjectPair in project ldapsdk by pingidentity.

the class ServerSetBlacklistManagerTestCase method testCompleteSettings.

/**
 * Tests the blacklist manager with a complete set of options.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompleteSettings() throws Exception {
    // Create a pair of in-memory directory server instances to use for testing.
    final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    cfg.addAdditionalBindCredentials("cn=Directory Manager", "password");
    final InMemoryDirectoryServer ds1 = new InMemoryDirectoryServer(cfg);
    ds1.startListening();
    final InMemoryDirectoryServer ds2 = new InMemoryDirectoryServer(cfg);
    ds2.startListening();
    // Create a server set and a blacklist manager.
    final String host = "localhost";
    final int port1 = ds1.getListenPort();
    final int port2 = ds2.getListenPort();
    final SocketFactory socketFactory = SocketFactory.getDefault();
    final LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
    final BindRequest bindRequest = new SimpleBindRequest("cn=Directory Manager", "password");
    final PostConnectProcessor postConnectProcessor = new TestPostConnectProcessor(null, null);
    final RoundRobinServerSet serverSet = new RoundRobinServerSet(new String[] { host, host }, new int[] { port1, port2 }, socketFactory, connectionOptions, bindRequest, postConnectProcessor);
    final ServerSetBlacklistManager blacklistManager = new ServerSetBlacklistManager(serverSet, socketFactory, connectionOptions, bindRequest, postConnectProcessor, 1L);
    // Validate the blacklist when it should be empty.
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the first directory server instance and add it to the blacklist.
    ds1.shutDown(true);
    final LDAPConnectionPoolHealthCheck healthCheck = new GetEntryLDAPConnectionPoolHealthCheck("", 10_000L, false, false, false, false, false, false);
    blacklistManager.addToBlacklist(host, port1, healthCheck);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the second directory server instance and add it to the blacklist.
    ds2.shutDown(true);
    blacklistManager.addToBlacklist(new ObjectPair<>(host, port2), healthCheck);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Sleep for at least 10 milliseconds to ensure that the blacklist manager
    // has had plenty of time to fail to re-establish a connection to the
    // blacklisted servers.
    Thread.sleep(10L);
    // Start the first directory server instance and wait for it to be removed
    // from the blacklist.
    ds1.startListening();
    long stopWaitingTime = System.currentTimeMillis() + 60_000L;
    while (System.currentTimeMillis() < stopWaitingTime) {
        if (blacklistManager.isBlacklisted(host, port1)) {
            Thread.sleep(1L);
        } else {
            break;
        }
    }
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Start the second directory server instance and wait for it to be removed
    // from the blacklist.
    ds2.startListening();
    stopWaitingTime = System.currentTimeMillis() + 60_000L;
    while (System.currentTimeMillis() < stopWaitingTime) {
        if (blacklistManager.isBlacklisted(host, port2)) {
            Thread.sleep(1L);
        } else {
            break;
        }
    }
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 0);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Stop the instances again and re-add them to the blacklist.
    ds1.shutDown(true);
    ds2.shutDown(true);
    blacklistManager.addToBlacklist(new ObjectPair<>(host, port1), healthCheck);
    blacklistManager.addToBlacklist(host, port2, healthCheck);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Sleep for at least 10 milliseconds.
    Thread.sleep(10L);
    // With the Directory Server instances still down, manually remove the first
    // server from the blacklist.
    blacklistManager.removeFromBlacklist(host, port1);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 1);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 1);
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Manually remove the second server from the blacklist.
    blacklistManager.removeFromBlacklist(new ObjectPair<>(host, port2));
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Re-add both servers to the blacklist.
    blacklistManager.addToBlacklist(host, port1, healthCheck);
    blacklistManager.addToBlacklist(host, port2, healthCheck);
    assertFalse(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 2);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertFalse(blacklistManager.getBlacklistedServers().isEmpty());
    assertEquals(blacklistManager.getBlacklistedServers().size(), 2);
    assertTrue(blacklistManager.isBlacklisted(host, port1));
    assertTrue(blacklistManager.isBlacklisted(host, port2));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertTrue(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    // Clear the blacklist.
    blacklistManager.clear();
    assertTrue(blacklistManager.isEmpty());
    assertEquals(blacklistManager.size(), 0);
    assertNotNull(blacklistManager.getBlacklistedServers());
    assertTrue(blacklistManager.getBlacklistedServers().isEmpty());
    assertFalse(blacklistManager.isBlacklisted(host, port1));
    assertFalse(blacklistManager.isBlacklisted(host, port2));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port1)));
    assertFalse(blacklistManager.isBlacklisted(new ObjectPair<>(host, port2)));
    assertNotNull(blacklistManager.toString());
    blacklistManager.shutDown();
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) SocketFactory(javax.net.SocketFactory) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) ObjectPair(com.unboundid.util.ObjectPair) Test(org.testng.annotations.Test)

Example 5 with ObjectPair

use of com.unboundid.util.ObjectPair in project ldapsdk by pingidentity.

the class MultiUpdateExtendedResultTestCase method testSuccessWithResults.

/**
 * Tests the behavior when creating a success result that contains multiple
 * operation results.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessWithResults() throws Exception {
    final Control[] opControls = { new Control("1.2.3.4"), new Control("1.2.3.5", true) };
    final ArrayList<ObjectPair<OperationType, LDAPResult>> results = new ArrayList<ObjectPair<OperationType, LDAPResult>>(5);
    results.add(new ObjectPair<OperationType, LDAPResult>(OperationType.ADD, new LDAPResult(-1, ResultCode.ADMIN_LIMIT_EXCEEDED, null, null, null, opControls)));
    results.add(new ObjectPair<OperationType, LDAPResult>(OperationType.DELETE, new LDAPResult(-1, ResultCode.ASSERTION_FAILED)));
    results.add(new ObjectPair<OperationType, LDAPResult>(OperationType.EXTENDED, new PasswordModifyExtendedResult(-1, ResultCode.INVALID_CREDENTIALS, null, null, null, null, null)));
    results.add(new ObjectPair<OperationType, LDAPResult>(OperationType.MODIFY, new LDAPResult(-1, ResultCode.ATTRIBUTE_OR_VALUE_EXISTS)));
    results.add(new ObjectPair<OperationType, LDAPResult>(OperationType.MODIFY_DN, new LDAPResult(-1, ResultCode.UNWILLING_TO_PERFORM)));
    final Control[] controls = { new Control("1.2.3.6"), new Control("1.2.3.7", true) };
    MultiUpdateExtendedResult r = new MultiUpdateExtendedResult(1, ResultCode.SUCCESS, null, null, null, MultiUpdateChangesApplied.PARTIAL, results, controls);
    r = new MultiUpdateExtendedResult(r);
    assertNotNull(r.getResultCode());
    assertEquals(r.getResultCode(), ResultCode.SUCCESS);
    assertNull(r.getDiagnosticMessage());
    assertNull(r.getMatchedDN());
    assertNotNull(r.getReferralURLs());
    assertEquals(r.getReferralURLs().length, 0);
    assertNotNull(r.getChangesApplied());
    assertEquals(r.getChangesApplied(), MultiUpdateChangesApplied.PARTIAL);
    assertNotNull(r.getResults());
    assertEquals(r.getResults().size(), 5);
    assertEquals(r.getResults().get(0).getFirst(), OperationType.ADD);
    assertEquals(r.getResults().get(0).getSecond().getResultCode(), ResultCode.ADMIN_LIMIT_EXCEEDED);
    assertEquals(r.getResults().get(1).getFirst(), OperationType.DELETE);
    assertEquals(r.getResults().get(1).getSecond().getResultCode(), ResultCode.ASSERTION_FAILED);
    assertEquals(r.getResults().get(2).getFirst(), OperationType.EXTENDED);
    assertTrue(r.getResults().get(2).getSecond() instanceof ExtendedResult);
    assertEquals(r.getResults().get(2).getSecond().getResultCode(), ResultCode.INVALID_CREDENTIALS);
    assertEquals(r.getResults().get(3).getFirst(), OperationType.MODIFY);
    assertEquals(r.getResults().get(3).getSecond().getResultCode(), ResultCode.ATTRIBUTE_OR_VALUE_EXISTS);
    assertEquals(r.getResults().get(4).getFirst(), OperationType.MODIFY_DN);
    assertEquals(r.getResults().get(4).getSecond().getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
    assertNotNull(r.getResponseControls());
    assertEquals(r.getResponseControls().length, 2);
    assertNotNull(r.getExtendedResultName());
    assertNotNull(r.toString());
}
Also used : Control(com.unboundid.ldap.sdk.Control) PasswordModifyExtendedResult(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedResult) ArrayList(java.util.ArrayList) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) PasswordModifyExtendedResult(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedResult) OperationType(com.unboundid.ldap.sdk.OperationType) ObjectPair(com.unboundid.util.ObjectPair) Test(org.testng.annotations.Test)

Aggregations

ObjectPair (com.unboundid.util.ObjectPair)57 ArrayList (java.util.ArrayList)35 NotNull (com.unboundid.util.NotNull)23 LDAPException (com.unboundid.ldap.sdk.LDAPException)22 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)21 Control (com.unboundid.ldap.sdk.Control)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)13 DN (com.unboundid.ldap.sdk.DN)9 ArgumentException (com.unboundid.util.args.ArgumentException)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 ResultCode (com.unboundid.ldap.sdk.ResultCode)8 File (java.io.File)8 LinkedHashMap (java.util.LinkedHashMap)7 List (java.util.List)7 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)6 Map (java.util.Map)6 AbortedTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult)5 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5