ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [26/45] ignite git commit: IGNITE-2527: IndexOutOfBoundsException in scheduler future. Reviewed and merged by Denis Magda (dmagda@gridgain.com).
Date Wed, 20 Jul 2016 09:29:37 GMT
IGNITE-2527: IndexOutOfBoundsException in scheduler future.
Reviewed and merged by Denis Magda (dmagda@gridgain.com).


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6cba20f4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6cba20f4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6cba20f4

Branch: refs/heads/ignite-1232-1
Commit: 6cba20f4e772d6a7e32cd899dfb7ff48f52f6c1f
Parents: 4a2a08b
Author: Milap Wadhwa <milap.wadhwa@gmail.com>
Authored: Tue Jul 19 13:05:21 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Tue Jul 19 13:05:21 2016 +0300

----------------------------------------------------------------------
 .../ignite/scheduler/SchedulerFuture.java       |  5 ++--
 .../processors/schedule/ScheduleFutureImpl.java |  7 ++++-
 .../schedule/GridScheduleSelfTest.java          | 27 ++++++++++++++++++--
 3 files changed, 34 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6cba20f4/modules/core/src/main/java/org/apache/ignite/scheduler/SchedulerFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/scheduler/SchedulerFuture.java b/modules/core/src/main/java/org/apache/ignite/scheduler/SchedulerFuture.java
index 4dcefc6..df4a3d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/scheduler/SchedulerFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/scheduler/SchedulerFuture.java
@@ -94,7 +94,8 @@ public interface SchedulerFuture<R> extends IgniteFuture<R>
{
      *
      * @param cnt Array length.
      * @param start Start timestamp.
-     * @return Array of the next execution times in milliseconds.
+     * @return Array of the next execution times in milliseconds or an empty array if there
is no next execution time
+     *         scheduled.
      * @throws IgniteException Thrown in case of any errors.
      */
     public long[] nextExecutionTimes(int cnt, long start) throws IgniteException;
@@ -116,7 +117,7 @@ public interface SchedulerFuture<R> extends IgniteFuture<R>
{
     /**
      * Gets next execution time of scheduled task.
      *
-     * @return Next execution time in milliseconds.
+     * @return Next execution time in milliseconds or {@code 0} if there is no next execution
time.
      * @throws IgniteException Thrown in case of any errors.
      */
     public long nextExecutionTime() throws IgniteException;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6cba20f4/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/ScheduleFutureImpl.java
----------------------------------------------------------------------
diff --git a/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/ScheduleFutureImpl.java
b/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/ScheduleFutureImpl.java
index 5a86019..ac23a79 100644
--- a/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/ScheduleFutureImpl.java
+++ b/modules/schedule/src/main/java/org/apache/ignite/internal/processors/schedule/ScheduleFutureImpl.java
@@ -60,6 +60,9 @@ class ScheduleFutureImpl<R> implements SchedulerFuture<R> {
     /** Empty time array. */
     private static final long[] EMPTY_TIMES = new long[] {};
 
+    /** No next execution time constant. **/
+    private static final long NO_NEXT_EXECUTION_TIME = 0;
+
     /** Identifier generated by cron scheduler. */
     private volatile String id;
 
@@ -450,7 +453,9 @@ class ScheduleFutureImpl<R> implements SchedulerFuture<R>
{
 
     /** {@inheritDoc} */
     @Override public long nextExecutionTime() {
-        return nextExecutionTimes(1, U.currentTimeMillis())[0];
+        long[] execTimes = nextExecutionTimes(1, U.currentTimeMillis());
+
+        return execTimes == EMPTY_TIMES ? NO_NEXT_EXECUTION_TIME : execTimes[0];
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/6cba20f4/modules/schedule/src/test/java/org/apache/ignite/internal/processors/schedule/GridScheduleSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/schedule/src/test/java/org/apache/ignite/internal/processors/schedule/GridScheduleSelfTest.java
b/modules/schedule/src/test/java/org/apache/ignite/internal/processors/schedule/GridScheduleSelfTest.java
index dec2103..b2463b4 100644
--- a/modules/schedule/src/test/java/org/apache/ignite/internal/processors/schedule/GridScheduleSelfTest.java
+++ b/modules/schedule/src/test/java/org/apache/ignite/internal/processors/schedule/GridScheduleSelfTest.java
@@ -333,8 +333,30 @@ public class GridScheduleSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Waits until method {@link org.apache.ignite.scheduler.SchedulerFuture#last()} returns
not a null value. Tries to call specified number
-     * of attempts with 100ms interval between them.
+     * @throws Exception If failed.
+     */
+    public void testNoNextExecutionTime() throws Exception {
+        SchedulerFuture<Integer> future = grid(0).scheduler().scheduleLocal(() ->
1, "{55} 53 3/5 * * *");
+
+        try {
+            future.get();
+
+            fail("Accepted wrong cron expression");
+        }
+        catch (IgniteException e) {
+            assertTrue(e.getMessage().startsWith("Invalid cron expression in schedule pattern"));
+        }
+
+        assertTrue(future.isDone());
+
+        assertEquals(0, future.nextExecutionTime());
+
+        assertEquals(0, future.nextExecutionTimes(2, System.currentTimeMillis()).length);
+    }
+
+    /**
+     * Waits until method {@link org.apache.ignite.scheduler.SchedulerFuture#last()} returns
not a null value. Tries to
+     * call specified number of attempts with 100ms interval between them.
      *
      * @param fut Schedule future to call method on.
      * @param attempts Max number of attempts to try.
@@ -383,6 +405,7 @@ public class GridScheduleSelfTest extends GridCommonAbstractTest {
             execCntr.incrementAndGet();
         }
     }
+
     /**
      * Test callable job.
      */


Mime
View raw message