From 1181fc29fead83c7c0d49ad697dc8f71f7338b0a Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Wed, 22 Nov 2006 11:41:33 +0000
Subject: [PATCH] move ProtocolWindowTest to synchronization because it needs the whole synchronization code to be working.
---
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java | 6
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java | 176 ++++++++++++++++++++++++----------
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java | 111 +++++++++++----------
3 files changed, 185 insertions(+), 108 deletions(-)
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
similarity index 98%
rename from opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
rename to opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
index ec9c1ab..f9d43ba 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/protocol/ProtocolWindowTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/ProtocolWindowTest.java
@@ -25,7 +25,7 @@
* Portions Copyright 2006 Sun Microsystems, Inc.
*/
-package org.opends.server.synchronization.protocol;
+package org.opends.server.synchronization;
import static org.opends.server.loggers.Error.logError;
import static org.testng.Assert.*;
@@ -74,7 +74,7 @@
* Test the contructors, encoders and decoders of the synchronization AckMsg,
* ModifyMsg, ModifyDnMsg, AddMsg and Delete Msg
*/
-public class ProtocolWindowTest
+public class ProtocolWindowTest extends SynchronizationTestCase
{
private static final int WINDOW_SIZE = 10;
private static final int CHANGELOG_QUEUE_SIZE = 100;
@@ -177,7 +177,7 @@
tmp.getOperationalAttributes());
addOp.run();
entryList.add(personEntry);
- assertNotNull(DirectoryServer.getEntry(personEntry.getDN()),
+ assertTrue(DirectoryServer.entryExists(personEntry.getDN()),
"The Add Entry operation failed");
// Check if the client has received the msg
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
index 69dd07f..dae2748 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/StressTest.java
@@ -75,16 +75,11 @@
* Test the contructors, encoders and decoders of the synchronization AckMsg,
* ModifyMsg, ModifyDnMsg, AddMsg and Delete Msg
*/
-public class StressTest extends MonitorProvider
+public class StressTest extends SynchronizationTestCase
{
private static final String SYNCHRONIZATION_STRESS_TEST =
"Synchronization Stress Test";
- public StressTest()
- {
- super("synchronization Stress Test");
- }
-
/**
* The internal connection used for operation
*/
@@ -156,7 +151,8 @@
cleanEntries();
ChangelogBroker broker = openChangelogSession(baseDn, (short) 18);
- DirectoryServer.registerMonitorProvider(this);
+ Monitor monitor = new Monitor("stress test monitor");
+ DirectoryServer.registerMonitorProvider(monitor);
try {
/*
@@ -186,7 +182,7 @@
tmp.getOperationalAttributes());
addOp.run();
entryList.add(personEntry);
- assertNotNull(DirectoryServer.getEntry(personEntry.getDN()),
+ assertTrue(DirectoryServer.entryExists(personEntry.getDN()),
"The Add Entry operation failed");
// Check if the client has received the msg
@@ -457,50 +453,6 @@
entryList.add(synchroServerEntry);
}
- @Override
- public List<Attribute> getMonitorData()
- {
- Attribute attr;
- if (reader == null)
- attr = new Attribute("received-messages", "not yet started");
- else
- attr = new Attribute("received-messages",
- String.valueOf(reader.getCurrentCount()));
- List<Attribute> list = new LinkedList<Attribute>();
- list.add(attr);
- attr = new Attribute("base-dn", "ou=People,dc=example,dc=com");
- list.add(attr);
- return list;
- }
-
- @Override
- public String getMonitorInstanceName()
- {
- return SYNCHRONIZATION_STRESS_TEST;
- }
-
- @Override
- public long getUpdateInterval()
- {
- // we don't wont to do polling on this monitor
- return 0;
- }
-
- @Override
- public void initializeMonitorProvider(ConfigEntry configEntry)
- throws ConfigException, InitializationException
- {
- // nothing to do
-
- }
-
- @Override
- public void updateMonitorData()
- {
- // nothing to do
-
- }
-
private class BrokerWriter extends Thread
{
int count;
@@ -605,4 +557,59 @@
return count;
}
}
+
+ private class Monitor extends MonitorProvider
+ {
+ protected Monitor(String threadName)
+ {
+ super(threadName);
+ }
+
+ @Override
+ public List<Attribute> getMonitorData()
+ {
+ Attribute attr;
+ if (reader == null)
+ attr = new Attribute("received-messages", "not yet started");
+ else
+ attr = new Attribute("received-messages",
+ String.valueOf(reader.getCurrentCount()));
+ List<Attribute> list = new LinkedList<Attribute>();
+ list.add(attr);
+ attr = new Attribute("base-dn", "ou=People,dc=example,dc=com");
+ list.add(attr);
+ return list;
+ }
+
+ @Override
+ public String getMonitorInstanceName()
+ {
+ return SYNCHRONIZATION_STRESS_TEST;
+ }
+
+ @Override
+ public void updateMonitorData()
+ {
+ // nothing to do
+
+ }
+
+ @Override
+ public void initializeMonitorProvider(ConfigEntry configEntry)
+ throws ConfigException, InitializationException
+ {
+ // nothing to do
+
+ }
+
+ @Override
+ public long getUpdateInterval()
+ {
+ // we don't wont to do polling on this monitor
+ return 0;
+ }
+
+
+
+ }
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
index d5aff11..89609f1 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/UpdateOperationTest.java
@@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.concurrent.locks.Lock;
import org.opends.server.TestCaseUtils;
import org.opends.server.plugins.ShortCircuitPlugin;
@@ -688,7 +689,7 @@
tmp.getOperationalAttributes());
addOp.run();
entryList.add(personEntry);
- assertNotNull(DirectoryServer.getEntry(personEntry.getDN()),
+ assertTrue(DirectoryServer.entryExists(personEntry.getDN()),
"The Add Entry operation failed");
// Check if the client has received the msg
@@ -731,11 +732,10 @@
.decode("uid=new person"), true, DN
.decode("ou=People,dc=example,dc=com"));
modDNOp.run();
- assertNotNull(DirectoryServer.getEntry(newDN),
+ assertTrue(DirectoryServer.entryExists(newDN),
"The MOD_DN operation didn't create the new person entry");
- assertNull(DirectoryServer.getEntry(personEntry.getDN()),
+ assertFalse(DirectoryServer.entryExists(personEntry.getDN()),
"The MOD_DN operation didn't delete the old person entry");
- entryList.add(DirectoryServer.getEntry(newDN));
// See if the client has received the msg
msg = broker.receive();
@@ -748,15 +748,13 @@
"The received MODIFY_DN message is not for the excepted DN");
// Delete the entry
- Entry newPersonEntry = DirectoryServer.getEntry(newDN) ;
DeleteOperation delOp = new DeleteOperation(connection,
InternalClientConnection.nextOperationID(), InternalClientConnection
.nextMessageID(), null, DN
.decode("uid= new person,ou=People,dc=example,dc=com"));
delOp.run();
- assertNull(DirectoryServer.getEntry(newDN),
+ assertFalse(DirectoryServer.entryExists(newDN),
"Unable to delete the new person Entry");
- entryList.remove(newPersonEntry);
// See if the client has received the msg
msg = broker.receive();
@@ -884,29 +882,53 @@
private boolean checkEntryHasAttribute(DN dn, String attrTypeStr,
String valueString, int timeout, boolean hasAttribute) throws Exception
{
- // Wait no more than 1 second (synchro operation has to be sent,
- // received and replay)
boolean found;
- int i = timeout/50;
- if (i<1)
- i=1;
+ int count = timeout/100;
+ if (count<1)
+ count=1;
do
{
- Entry newEntry = DirectoryServer.getEntry(personWithUUIDEntry.getDN());
- if (newEntry == null)
- fail("The entry " + personWithUUIDEntry.getDN() +
- " has incorrectly been deleted from the database.");
- List<Attribute> tmpAttrList = newEntry.getAttribute(attrTypeStr);
- Attribute tmpAttr = tmpAttrList.get(0);
+ Entry newEntry;
+ Lock lock = null;
+ for (int j=0; j < 3; j++)
+ {
+ lock = LockManager.lockRead(dn);
+ if (lock != null)
+ {
+ break;
+ }
+ }
+
+ if (lock == null)
+ {
+ throw new Exception("could not lock entry " + dn);
+ }
- AttributeType attrType =
- DirectoryServer.getAttributeType(attrTypeStr, true);
- found = tmpAttr.hasValue(new AttributeValue(attrType, valueString));
- i-- ;
+ try
+ {
+ newEntry = DirectoryServer.getEntry(personWithUUIDEntry.getDN());
+
+
+ if (newEntry == null)
+ fail("The entry " + personWithUUIDEntry.getDN() +
+ " has incorrectly been deleted from the database.");
+ List<Attribute> tmpAttrList = newEntry.getAttribute(attrTypeStr);
+ Attribute tmpAttr = tmpAttrList.get(0);
+
+ AttributeType attrType =
+ DirectoryServer.getAttributeType(attrTypeStr, true);
+ found = tmpAttr.hasValue(new AttributeValue(attrType, valueString));
+
+ }
+ finally
+ {
+ LockManager.unlock(dn, lock);
+ }
+
if (found != hasAttribute)
- Thread.sleep(50);
- } while ((i > 0) && (found != hasAttribute));
+ Thread.sleep(100);
+ } while ((--count > 0) && (found != hasAttribute));
return found;
}
@@ -916,54 +938,102 @@
*/
private String getEntryUUID(DN dn) throws Exception
{
- // Wait no more than 1 second (synchro operation has to be sent,
- // received and replay)
- int i = 10;
- if (i<1)
- i=1;
+ Entry newEntry;
+ int count = 10;
+ if (count<1)
+ count=1;
String found = null;
- while ((i> 0) && (found == null))
+ while ((count> 0) && (found == null))
{
Thread.sleep(100);
- Entry newEntry = DirectoryServer.getEntry(dn);
- if (newEntry != null)
+
+ Lock lock = null;
+ for (int i=0; i < 3; i++)
{
- List<Attribute> tmpAttrList = newEntry.getAttribute("entryuuid");
- Attribute tmpAttr = tmpAttrList.get(0);
-
- LinkedHashSet<AttributeValue> vals = tmpAttr.getValues();
-
- for (AttributeValue val : vals)
+ lock = LockManager.lockRead(dn);
+ if (lock != null)
{
- found = val.getStringValue();
break;
}
}
+
+ if (lock == null)
+ {
+ throw new Exception("could not lock entry " + dn);
+ }
+
+ try
+ {
+ newEntry = DirectoryServer.getEntry(dn);
+
+ if (newEntry != null)
+ {
+ List<Attribute> tmpAttrList = newEntry.getAttribute("entryuuid");
+ Attribute tmpAttr = tmpAttrList.get(0);
+
+ LinkedHashSet<AttributeValue> vals = tmpAttr.getValues();
+
+ for (AttributeValue val : vals)
+ {
+ found = val.getStringValue();
+ break;
+ }
+ }
+ }
+ finally
+ {
+ LockManager.unlock(dn, lock);
+ }
}
return found;
}
/**
* Retrieves an entry from the local Directory Server.
- *
- * @throws InterruptedException
- * @throws DirectoryException
+ * @throws Exception When the entry cannot be locked.
*/
private Entry getEntry(DN dn, int timeout, boolean exist)
- throws InterruptedException, DirectoryException
+ throws Exception
{
- Entry newEntry = null ;
- int i = timeout/200;
- if (i<1)
- i=1;
- newEntry = DirectoryServer.getEntry(dn);
- while ((i> 0) && ((newEntry == null) == exist))
+ int count = timeout/200;
+ if (count<1)
+ count=1;
+ boolean found = DirectoryServer.entryExists(dn);
+ while ((count> 0) && (found != exist))
{
Thread.sleep(200);
- newEntry = DirectoryServer.getEntry(dn);
- i--;
+
+ found = DirectoryServer.entryExists(dn);
+ count--;
}
- return newEntry;
+
+ Lock lock = null;
+ for (int i=0; i < 3; i++)
+ {
+ lock = LockManager.lockRead(dn);
+ if (lock != null)
+ {
+ break;
+ }
+ }
+
+ if (lock == null)
+ {
+ throw new Exception("could not lock entry " + dn);
+ }
+
+ try
+ {
+ Entry entry = DirectoryServer.getEntry(dn);
+ if (entry == null)
+ return null;
+ else
+ return entry.duplicate();
+ }
+ finally
+ {
+ LockManager.unlock(dn, lock);
+ }
}
/**
@@ -1082,7 +1152,7 @@
long initialCount = getReplayedUpdatesCount();
// Get the UUID of the test entry.
- Entry resultEntry = DirectoryServer.getEntry(tmp.getDN());
+ Entry resultEntry = getEntry(tmp.getDN(), 1, true);
AttributeType uuidType = DirectoryServer.getAttributeType("entryuuid");
String uuid =
resultEntry.getAttributeValue(uuidType,
--
Gitblit v1.10.0