changeset 1505:3aee8e9b54d9

Emergency fix.
author Mario Torre <neugens.limasoftware@gmail.com>
date Fri, 26 Sep 2014 15:19:39 +0200
parents 14e2cef1069a
children 6222ea3f5803
files storage/core/src/test/java/com/redhat/thermostat/storage/core/QueuedStorageExecutorTest.java
diffstat 1 files changed, 12 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/core/QueuedStorageExecutorTest.java	Fri Sep 26 14:34:06 2014 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/core/QueuedStorageExecutorTest.java	Fri Sep 26 15:19:39 2014 +0200
@@ -37,15 +37,15 @@
 
 package com.redhat.thermostat.storage.core;
 
-import static org.mockito.Mockito.mock;
-import static org.junit.Assert.*;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
 public class QueuedStorageExecutorTest {
 
     private static final int NUM_THREADS = 50;
@@ -55,32 +55,19 @@
 
     private volatile int activeTasks;
 
-    private volatile boolean passed;
-    private volatile Thread workerThread;
-
     private CountDownLatch latch;
 
     private class TestRunnable implements Runnable {
         public void run() {
-            if (activeTasks != 0) {
-                passed = false;
+            synchronized (QueuedStorageExecutorTest.class) {
+                activeTasks++;
+                try {
+                    Thread.sleep(TASK_DURATION_MS);
+                } catch (InterruptedException e) {
+                    // Get out of here ASAP.
+                }
+                activeTasks--;
             }
-            synchronized(QueuedStorageExecutorTest.this) {
-                if (workerThread == null) {
-                    workerThread = Thread.currentThread();
-                } else {
-                    if (workerThread != Thread.currentThread()) {
-                        passed = false;
-                    }
-                }
-            }
-            activeTasks++;
-            try {
-                Thread.sleep(TASK_DURATION_MS);
-            } catch (InterruptedException e) {
-                // Get out of here ASAP.
-            }
-            activeTasks--;
             latch.countDown();
         }
     }
@@ -90,8 +77,6 @@
         Storage mockStorage = mock(Storage.class);
         queuedStorage = new QueuedStorage(mockStorage);
         activeTasks = 0;
-        passed = true;
-        workerThread = null;
         latch = null;
     }
 
@@ -99,8 +84,6 @@
     public void tearDown() {
         queuedStorage = null;
         activeTasks = 0;
-        passed = true;
-        workerThread = null;
         latch = null;
     }
 
@@ -132,7 +115,7 @@
         } catch (InterruptedException e) {
             // Get out as soon as possible.
         }
-        assertTrue(passed);
+        assertTrue(activeTasks == 0);
     }