Author: shawkins
Date: 2011-10-03 11:09:29 -0400 (Mon, 03 Oct 2011)
New Revision: 3513
Added:
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/CancellationTimer.java
Log:
TEIID-1765 fix for invalid comparison method
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/CancellationTimer.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/CancellationTimer.java 2011-10-03
12:20:17 UTC (rev 3512)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/CancellationTimer.java 2011-10-03
15:09:29 UTC (rev 3513)
@@ -23,7 +23,7 @@
package org.teiid.jdbc;
import java.util.TreeSet;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import org.jboss.logging.Logger;
@@ -32,11 +32,11 @@
*/
public class CancellationTimer {
- private static AtomicInteger id = new AtomicInteger();
+ private static AtomicLong id = new AtomicLong();
static abstract class CancelTask implements Runnable, Comparable<CancelTask> {
- long endTime;
- int seqId = id.get();
+ final long endTime;
+ final long seqId = id.get();
public CancelTask(long delay) {
this.endTime = System.currentTimeMillis() + delay;
@@ -44,21 +44,14 @@
@Override
public int compareTo(CancelTask o) {
- int result = Long.signum(this.endTime = o.endTime);
+ int result = Long.signum(this.endTime - o.endTime);
if (result == 0) {
- return seqId = o.seqId;
+ return Long.signum(seqId - o.seqId);
}
return result;
}
- @Override
public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof CancelTask)) {
- return false;
- }
- return this.compareTo((CancelTask)obj) == 0;
+ return obj == this;
}
}
@@ -118,5 +111,9 @@
this.notifyAll();
}
}
+
+ synchronized int getQueueSize() {
+ return cancelQueue.size();
+ }
}
Added: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
(rev 0)
+++
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java 2011-10-03
15:09:29 UTC (rev 3513)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.teiid.jdbc.CancellationTimer.CancelTask;
+
+@SuppressWarnings("nls")
+public class TestCancellationTimer {
+
+ private final class SimpleCancelTask extends CancelTask {
+ private SimpleCancelTask(long delay) {
+ super(delay);
+ }
+
+ @Override
+ public void run() {
+ }
+ }
+
+ @Test public void testRemove() {
+ CancellationTimer ct = new CancellationTimer("foo");
+ SimpleCancelTask sct = new SimpleCancelTask(20000);
+ ct.add(sct);
+ SimpleCancelTask sct1 = new SimpleCancelTask(30000);
+ ct.add(sct1);
+ SimpleCancelTask sct2 = new SimpleCancelTask(10000);
+ ct.add(sct2);
+ assertEquals(3, ct.getQueueSize());
+ ct.remove(sct2);
+ ct.remove(sct1);
+ ct.remove(sct);
+ assertEquals(0, ct.getQueueSize());
+ }
+
+}
Property changes on:
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Show replies by date