[teiid-commits] teiid SVN: r3514 - in trunk/client/src: test/java/org/teiid/jdbc and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Oct 3 11:12:46 EDT 2011


Author: shawkins
Date: 2011-10-03 11:12:45 -0400 (Mon, 03 Oct 2011)
New Revision: 3514

Added:
   trunk/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
Modified:
   trunk/client/src/main/java/org/teiid/jdbc/CancellationTimer.java
Log:
TEIID-1765 fix for invalid comparison method

Modified: trunk/client/src/main/java/org/teiid/jdbc/CancellationTimer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/CancellationTimer.java	2011-10-03 15:09:29 UTC (rev 3513)
+++ trunk/client/src/main/java/org/teiid/jdbc/CancellationTimer.java	2011-10-03 15:12:45 UTC (rev 3514)
@@ -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: trunk/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java	                        (rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java	2011-10-03 15:12:45 UTC (rev 3514)
@@ -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;
+
+ at 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: trunk/client/src/test/java/org/teiid/jdbc/TestCancellationTimer.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the teiid-commits mailing list