opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java
@@ -39,8 +39,6 @@ import org.opends.server.TestCaseUtils; import org.opends.server.api.Backend; import org.opends.server.api.Backend.BackendOperation; import org.opends.server.backends.task.Task; import org.opends.server.backends.task.TaskState; import org.opends.server.core.AddOperation; import org.opends.server.core.CompareOperation; import org.opends.server.core.DeleteOperation; @@ -103,8 +101,8 @@ "config" + File.separator + "MakeLDIF"; LdifFileWriter.makeLdif(ldifFile.getPath(), resourcePath, templateFilePath); String taskDN = "ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks"; DN taskDN = DN.valueOf("ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks"); TestCaseUtils.addEntry( "dn: " + taskDN, @@ -115,9 +113,7 @@ "ds-task-import-backend-id: ldifRoot", "ds-task-import-ldif-file: " + ldifFile.getAbsolutePath()); Task t = TasksTestCase.getCompletedTask(DN.valueOf(taskDN)); assertNotNull(t); assertEquals(t.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); TasksTestCase.waitTaskCompletedSuccessfully(taskDN); } @@ -129,8 +125,7 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddAndDelete() throws Exception public void testAddAndDelete() throws Exception { // Add a number of entries to the server. int resultCode = TestCaseUtils.applyModifications(false, @@ -700,9 +695,7 @@ "ds-task-export-backend-id: ldifRoot", "ds-task-export-ldif-file: " + tempFilePath); Task t = TasksTestCase.getCompletedTask(DN.valueOf(taskDN)); assertNotNull(t); assertEquals(t.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); TasksTestCase.waitTaskCompletedSuccessfully(DN.valueOf(taskDN)); } opendj-server-legacy/src/test/java/org/opends/server/backends/task/TaskBackendTestCase.java
@@ -47,9 +47,7 @@ import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; /** * A set of test cases that can be used to test the task backend. */ /** A set of test cases that can be used to test the task backend. */ public class TaskBackendTestCase extends BackendTestCase { @@ -186,11 +184,9 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testDeleteCompletedTask() throws Exception public void testDeleteCompletedTask() throws Exception { // Schedule a task to start immediately that will simply sleep for 30 // seconds. // Schedule a task to start immediately that will simply sleep for 30s String taskID = "testDeleteCompltedTask"; String taskDN = "ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=tasks"; @@ -203,10 +199,8 @@ "ds-task-class-name: org.opends.server.tasks.DummyTask"); // Wait until the task has completed. Task task = TasksTestCase.getCompletedTask(DN.valueOf(taskDN)); assertTrue(TaskState.isDone(task.getTaskState())); // Wait until the task is done. TasksTestCase.getDoneTask(DN.valueOf(taskDN)); // Perform a modification to delete that task. int resultCode = TestCaseUtils.applyModifications(true, @@ -288,8 +282,7 @@ public void testModifyRunningTask() throws Exception { // Schedule a task to start immediately that will simply sleep for 5 // minutes. // Schedule a task to start immediately that will simply sleep for 5 minutes String taskID = "testModifyRunningTask"; String taskDN = "ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=tasks"; @@ -337,9 +330,8 @@ // We may have to wait for the task to register as done, but it should // definitely be done before it would have stopped normally. task = TasksTestCase.getCompletedTask(DN.valueOf(taskDN)); task = TasksTestCase.getDoneTask(DN.valueOf(taskDN)); assertTrue(System.currentTimeMillis() - startTime < 300000L); assertTrue(TaskState.isDone(task.getTaskState())); // Perform a modification to delete that task unless @@ -358,8 +350,7 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testModifyCompletedTask() throws Exception public void testModifyCompletedTask() throws Exception { // Schedule a task to start and complete immediately. String taskID = "testModifyCompltedTask"; @@ -373,10 +364,8 @@ "ds-task-id: " + taskID, "ds-task-class-name: org.opends.server.tasks.DummyTask"); // Wait until the task has completed. Task task = TasksTestCase.getCompletedTask(DN.valueOf(taskDN)); assertTrue(TaskState.isDone(task.getTaskState())); // Wait until the task is done TasksTestCase.getDoneTask(DN.valueOf(taskDN)); // Perform a modification to update a non-state attribute. int resultCode = TestCaseUtils.applyModifications(true, opendj-server-legacy/src/test/java/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
@@ -26,30 +26,25 @@ */ package org.opends.server.tasks; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.testng.annotations.Test; import org.testng.annotations.BeforeClass; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.Schema; import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.opends.server.TestCaseUtils; import org.opends.server.backends.SchemaTestMatchingRuleImpl; import org.opends.server.backends.task.Task; import org.opends.server.backends.task.TaskState; import org.opends.server.core.DirectoryServer; import org.opends.server.core.SchemaConfigManager; import org.opends.server.schema.SchemaConstants; import org.opends.server.types.DN; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * Tests invocation of the import and export tasks, but does not aim to * thoroughly test the underlying backend implementations. @@ -63,8 +58,7 @@ * @throws Exception If an unexpected problem occurs. */ @BeforeClass public void startServer() throws Exception public void startServer() throws Exception { TestCaseUtils.startServer(); } @@ -130,13 +124,7 @@ }; File validFile = new File(schemaDirectory, "05-single-valid.ldif"); BufferedWriter writer = new BufferedWriter(new FileWriter(validFile)); for (String line : fileLines) { writer.write(line); writer.newLine(); } writer.close(); writeLines(validFile, fileLines); String taskDNStr = "ds-task-id=add-single-valid-file,cn=Scheduled Tasks,cn=Tasks"; @@ -151,8 +139,7 @@ "ds-task-schema-file-name: 05-single-valid.ldif"); assertEquals(resultCode, 0); Task task = getCompletedTask(DN.valueOf(taskDNStr)); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == beforeModifyTimestamp); } @@ -211,13 +198,7 @@ }; File validFile1 = new File(schemaDirectory, "05-multiple-valid-1.ldif"); BufferedWriter writer1 = new BufferedWriter(new FileWriter(validFile1)); for (String line : fileLines1) { writer1.write(line); writer1.newLine(); } writer1.close(); writeLines(validFile1, fileLines1); MatchingRule matchingRule2 = @@ -250,13 +231,7 @@ }; File validFile2 = new File(schemaDirectory, "05-multiple-valid-2.ldif"); BufferedWriter writer2 = new BufferedWriter(new FileWriter(validFile2)); for (String line : fileLines2) { writer2.write(line); writer2.newLine(); } writer2.close(); writeLines(validFile2, fileLines2); String taskDNStr = @@ -273,13 +248,22 @@ "ds-task-schema-file-name: 05-multiple-valid-2.ldif"); assertEquals(resultCode, 0); Task task = getCompletedTask(DN.valueOf(taskDNStr)); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == beforeModifyTimestamp); } private void writeLines(File file, String[] lines) throws IOException { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (String line : lines) { writer.write(line); writer.newLine(); } } } /** * Attempts to add a new file to the server schema in which the task entry @@ -367,14 +351,11 @@ "ds-task-schema-file-name: 05-empty.ldif"); assertEquals(resultCode, 0); Task task = getCompletedTask(DN.valueOf(taskDNStr)); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == beforeModifyTimestamp); } /** * Attempts to add a new file to the server schema in which the file exists * but does not contain a valid schema definition. @@ -388,9 +369,10 @@ String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath(); File invalidFile = new File(schemaDirectory, "05-invalid.ldif"); BufferedWriter writer = new BufferedWriter(new FileWriter(invalidFile)); writer.write("invalid"); writer.close(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(invalidFile))) { writer.write("invalid"); } String taskDNStr = "ds-task-id=add-invalid-file,cn=Scheduled Tasks,cn=Tasks"; @@ -407,4 +389,3 @@ invalidFile.delete(); } } opendj-server-legacy/src/test/java/org/opends/server/tasks/AllowedTaskTestCase.java
@@ -26,22 +26,16 @@ */ package org.opends.server.tasks; import org.testng.annotations.Test; import org.testng.annotations.BeforeClass; import org.opends.server.TestCaseUtils; import org.opends.server.backends.task.Task; import org.opends.server.backends.task.TaskState; import org.opends.server.protocols.ldap.LDAPResultCode; import org.opends.server.tools.LDAPModify; import org.opends.server.types.DN; import static org.testng.Assert.*; /** * Tests the ability of the server to control the set of tasks that are allowed * to be executed. @@ -124,10 +118,8 @@ assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), LDAPResultCode.SUCCESS); Task task = getCompletedTask(DN.valueOf( waitTaskCompletedSuccessfully(DN.valueOf( "ds-task-id=testAllowedTask 2,cn=Scheduled Tasks,cn=Tasks")); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); // Remove the task class from the set of allowed tasks and verify that we opendj-server-legacy/src/test/java/org/opends/server/tasks/DisconnectClientTaskTestCase.java
@@ -26,32 +26,22 @@ */ package org.opends.server.tasks; import java.net.Socket; import org.testng.annotations.Test; import org.testng.annotations.BeforeClass; import org.opends.server.TestCaseUtils; import org.forgerock.i18n.LocalizableMessage; import org.opends.server.backends.task.Task; import org.opends.server.backends.task.TaskState; import org.forgerock.opendj.ldap.ByteString; import org.opends.server.TestCaseUtils; import org.opends.server.extensions.GetConnectionIDExtendedOperation; import org.opends.server.protocols.ldap.*; import org.opends.server.types.DN; import org.opends.server.util.StaticUtils; import org.forgerock.opendj.ldap.ByteString; import static org.testng.Assert.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; /** * Tests the disconnect client task. */ /** Tests the disconnect client task. */ public class DisconnectClientTaskTestCase extends TasksTestCase { @@ -127,13 +117,10 @@ "ds-task-disconnect-notify-client: true", "ds-task-disconnect-message: " + disconnectMessage); Task task = getCompletedTask(taskDN); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(taskDN); // Make sure that we get a notice of disconnection on the initial // connection. // Make sure that we get a notice of disconnection on the initial connection. message = r.readMessage(); extendedResponse = message.getExtendedResponseProtocolOp(); assertEquals(extendedResponse.getOID(), @@ -201,16 +188,12 @@ "ds-task-disconnect-connection-id: " + connectionID, "ds-task-disconnect-notify-client: false"); Task task = getCompletedTask(taskDN); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(taskDN); // Make sure that the client connection has been closed with no notice of // disconnection. // Make sure that the client connection has been closed with no notice of disconnection. assertNull(r.readMessage()); StaticUtils.close(s); } } opendj-server-legacy/src/test/java/org/opends/server/tasks/LockdownModeTaskTestCase.java
@@ -26,8 +26,6 @@ */ package org.opends.server.tasks; import java.net.InetAddress; import org.testng.annotations.Test; @@ -35,8 +33,6 @@ import org.testng.annotations.BeforeClass; import org.opends.server.TestCaseUtils; import org.opends.server.backends.task.Task; import org.opends.server.backends.task.TaskState; import org.opends.server.core.DirectoryServer; import org.opends.server.tools.LDAPSearch; import org.opends.server.tools.LDAPModify; @@ -44,11 +40,7 @@ import static org.testng.Assert.*; /** * Tests the enter and leave lockdown mode tasks. */ /** Tests the enter and leave lockdown mode tasks. */ public class LockdownModeTaskTestCase extends TasksTestCase { @@ -58,8 +50,7 @@ * @throws Exception If an unexpected problem occurs. */ @BeforeClass public void startServer() throws Exception public void startServer() throws Exception { TestCaseUtils.startServer(); } @@ -179,9 +170,7 @@ "-f", taskFile }; assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0); Task task = getCompletedTask(taskDN); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(taskDN); assertTrue(DirectoryServer.lockdownMode()); @@ -276,9 +265,7 @@ "-f", taskFile }; assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0); task = getCompletedTask(taskDN); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); waitTaskCompletedSuccessfully(taskDN); assertFalse(DirectoryServer.lockdownMode()); opendj-server-legacy/src/test/java/org/opends/server/tasks/TasksTestCase.java
@@ -52,9 +52,7 @@ import static org.opends.server.protocols.internal.Requests.*; import static org.testng.Assert.*; /** * A base class for all tasks test cases. */ /** A base class for all tasks test cases. */ @Test(groups = { "precommit", "tasks" }, sequential = true) public class TasksTestCase extends DirectoryServerTestCase { @@ -144,8 +142,6 @@ }); } /** * Retrieves the specified task from the server, waiting for it to finish all * the running its going to do before returning. @@ -157,7 +153,7 @@ * @throws Exception If an unexpected problem occurs. */ @Test(enabled=false) // This isn't a test method, but TestNG thinks it is. public static Task getCompletedTask(final DN taskEntryDN) throws Exception public static Task getDoneTask(final DN taskEntryDN) throws Exception { final Task task = getTask(taskEntryDN); @@ -176,4 +172,11 @@ } }); } public static void waitTaskCompletedSuccessfully(DN taskDN) throws Exception { Task task = getDoneTask(taskDN); assertNotNull(task); assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY); } }