You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2022/07/08 13:14:39 UTC

[turbine-core] branch trunk updated: Add JobQueueTest

This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/turbine-core.git


The following commit(s) were added to refs/heads/trunk by this push:
     new f574ec52 Add JobQueueTest
f574ec52 is described below

commit f574ec52e5406dbb27756a5add104ac3e53b4c0f
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Fri Jul 8 15:14:36 2022 +0200

    Add JobQueueTest
---
 .../turbine/services/schedule/JobQueueTest.java    | 95 ++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/src/test/org/apache/turbine/services/schedule/JobQueueTest.java b/src/test/org/apache/turbine/services/schedule/JobQueueTest.java
new file mode 100644
index 00000000..54d0cd77
--- /dev/null
+++ b/src/test/org/apache/turbine/services/schedule/JobQueueTest.java
@@ -0,0 +1,95 @@
+package org.apache.turbine.services.schedule;
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.turbine.util.TurbineException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit testing for JobQueue.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ */
+public class JobQueueTest
+{
+    private JobQueue<JobEntryNonPersistent> queue;
+    private JobEntryNonPersistent je1;
+    private JobEntryNonPersistent je2;
+
+    @Before
+    public void setUpBefore() throws Exception
+    {
+        queue = new JobQueue<>();
+
+        // Add a new job entry
+        je1 = new JobEntryNonPersistent(1,2,3,4,5,"je1");
+        je1.setJobId(1);
+
+        je2 = new JobEntryNonPersistent(0,2,3,4,5,"je2");
+        je2.setJobId(2);
+    }
+
+    /**
+     * Test job queue functions
+     * @throws TurbineException if the queue update fails
+     */
+    @Test
+    public void testJobQueue() throws TurbineException
+    {
+        assertNull(queue.getNext());
+
+        queue.add(je2);
+        queue.add(je1);
+        assertEquals(2, queue.list().size());
+
+        JobEntryNonPersistent je_a = queue.getNext();
+        assertNotNull(je_a);
+        assertEquals(je2, je_a);
+        assertEquals(1, queue.list().size());
+
+        JobEntryNonPersistent je_b = queue.getJob(je2);
+        assertNull(je_b);
+        JobEntryNonPersistent je_c = queue.getJob(je1);
+        assertNotNull(je_c);
+        assertEquals(je1, je_c);
+
+        je_c.setSecond(2);
+        queue.updateQueue(je_c);
+        assertEquals(1, queue.list().size());
+
+        je2.setSecond(3);
+        queue.updateQueue(je2);
+        JobEntryNonPersistent je_d = queue.getNext();
+        assertNotNull(je_d);
+        assertEquals(je1, je_d);
+        JobEntryNonPersistent je_e = queue.getNext();
+        assertNotNull(je_e);
+        assertEquals(je2, je_e);
+
+        // queue should now be empty
+        assertNull(queue.list());
+    }
+
+}