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

coulbeck
03.40.2006 c86d637ceac1c419cf8c5bb836f5a8438eae93c1
opendj-sdk/opends/src/server/org/opends/server/types/LockManager.java
@@ -127,7 +127,7 @@
   *          it was not possible to obtain a read lock for some
   *          reason.
   */
  public static final Lock tryLockRead(DN entryDN)
  public static Lock tryLockRead(DN entryDN)
  {
    assert debugEnter(CLASS_NAME, "tryLockRead",
                      String.valueOf(entryDN));
@@ -251,7 +251,7 @@
   *          it was not possible to obtain a read lock for some
   *          reason.
   */
  public static final Lock lockRead(DN entryDN)
  public static Lock lockRead(DN entryDN)
  {
    assert debugEnter(CLASS_NAME, "lockRead",
                      String.valueOf(entryDN));
@@ -277,7 +277,7 @@
   *          it was not possible to obtain a read lock for some
   *          reason.
   */
  public static final Lock lockRead(DN entryDN, long timeout)
  public static Lock lockRead(DN entryDN, long timeout)
  {
    assert debugEnter(CLASS_NAME, "lockRead", String.valueOf(entryDN),
                      String.valueOf(timeout));
@@ -416,7 +416,7 @@
   *          if it was not possible to obtain a write lock for some
   *          reason.
   */
  public static final Lock tryLockWrite(DN entryDN)
  public static Lock tryLockWrite(DN entryDN)
  {
    assert debugEnter(CLASS_NAME, "lockWrite",
                      String.valueOf(entryDN));
@@ -536,12 +536,12 @@
   *                  write lock.
   *
   * @return  The write lock that was acquired, or <CODE>null</CODE>
   *          if it was not possible to obtain a read lock for some
   *          if it was not possible to obtain a write lock for some
   *          reason.
   */
  public static final Lock lockWrite(DN entryDN)
  public static Lock lockWrite(DN entryDN)
  {
    assert debugEnter(CLASS_NAME, "lockRead",
    assert debugEnter(CLASS_NAME, "lockWrite",
                      String.valueOf(entryDN));
    return lockWrite(entryDN, DEFAULT_TIMEOUT);
@@ -563,7 +563,7 @@
   *          if it was not possible to obtain a read lock for some
   *          reason.
   */
  public static final Lock lockWrite(DN entryDN, long timeout)
  public static Lock lockWrite(DN entryDN, long timeout)
  {
    assert debugEnter(CLASS_NAME, "lockWrite",
                      String.valueOf(entryDN),
@@ -699,7 +699,7 @@
   *                  lock.
   * @param  lock     The read or write lock held for the entry.
   */
  public static final void unlock(DN entryDN, Lock lock)
  public static void unlock(DN entryDN, Lock lock)
  {
    assert debugEnter(CLASS_NAME, "unlock", String.valueOf(entryDN));
@@ -772,8 +772,6 @@
        // This lock isn't held so we can remove it from the table.
        entryLocks.remove(entryDN);
      }
      return;
    }
    catch (Exception e)
    {
@@ -786,7 +784,6 @@
                  "whether the lock for entry " + entryDN.toString() +
                  " can be removed:  " +
                  stackTraceToSingleLineString(e));
      return;
    }
    finally
    {
@@ -810,7 +807,7 @@
   *          specified entry.  If a lock object is returned, it may
   *          be possible to get information about who was holding it.
   */
  public static final ReentrantReadWriteLock destroyLock(DN entryDN)
  public static ReentrantReadWriteLock destroyLock(DN entryDN)
  {
    assert debugEnter(CLASS_NAME, "destroyLock",
                      String.valueOf(entryDN));
@@ -826,7 +823,7 @@
   *
   * @return  The number of entries currently held in the lock table.
   */
  public static final int lockTableSize()
  public static int lockTableSize()
  {
    assert debugEnter(CLASS_NAME, "lockTableSize");
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
@@ -29,10 +29,13 @@
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.ldap.*;
import org.opends.server.types.Control;
import org.opends.server.types.ResultCode;
import org.opends.server.types.Entry;
import org.opends.server.types.LockManager;
import org.opends.server.TestCaseUtils;
import org.opends.server.controls.LDAPAssertionRequestControl;
import org.opends.server.controls.ProxiedAuthV1Control;
@@ -41,9 +44,12 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.net.Socket;
public class CompareOperationTestCase extends OperationTestCase
{
@@ -589,4 +595,67 @@
    examineIncompleteOperation(compareOperation);
  }
  @Test(groups = "slow")
  public void testCompareWriteLock() throws Exception
  {
    // We need the operation to be run in a separate thread because we are going
    // to write lock the entry in the test case thread and check that the
    // compare operation does not proceed.
    // Establish a connection to the server.
    Socket s = new Socket("127.0.0.1", (int) TestCaseUtils.getServerLdapPort());
    try
    {
      ASN1Reader r = new ASN1Reader(s);
      ASN1Writer w = new ASN1Writer(s);
      r.setIOTimeout(15000);
      BindRequestProtocolOp bindRequest =
           new BindRequestProtocolOp(
                new ASN1OctetString("cn=Directory Manager"),
                3, new ASN1OctetString("password"));
      LDAPMessage message = new LDAPMessage(1, bindRequest);
      w.writeElement(message.encode());
      message = LDAPMessage.decode(r.readElement().decodeAsSequence());
      BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
      assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS);
      Lock writeLock = LockManager.lockWrite(entry.getDN());
      assertNotNull(writeLock);
      try
      {
        InvocationCounterPlugin.resetAllCounters();
        CompareRequestProtocolOp compareRequest =
          new CompareRequestProtocolOp(
               new ASN1OctetString(entry.getDN().toString()),
               "uid", new ASN1OctetString("rogasawara"));
        message = new LDAPMessage(2, compareRequest);
        w.writeElement(message.encode());
        message = LDAPMessage.decode(r.readElement().decodeAsSequence());
        CompareResponseProtocolOp compareResponse =
             message.getCompareResponseProtocolOp();
        assertEquals(compareResponse.getResultCode(),
                     DirectoryServer.getServerErrorResultCode().getIntValue());
        assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
        assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
        assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
        assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
      } finally
      {
        LockManager.unlock(entry.getDN(), writeLock);
      }
    } finally
    {
      s.close();
    }
  }
}