[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rhq-commits
Subject:    [rhq] Branch 'jay-avail' - modules/core
From:       mazz <mazz () fedoraproject ! org>
Date:       2013-11-26 23:05:52
Message-ID: 20131126230552.35FC260A35 () fedorahosted ! org
[Download RAW message or body]

 modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/AvailabilityProxyConcurrencyTest.java \
|  111 ++++++++++  1 file changed, 111 insertions(+)

New commits:
commit b2539ee14e487ed58dbf1f041f13420db14965f7
Author: John Mazzitelli <mazz@redhat.com>
Date:   Tue Nov 26 18:05:38 2013 -0500

    unit test that illustrates failure that is talked about in BZ 971556, comments #8 \
and 9.  this test is disabled for now, since it will fail.

diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/AvailabilityProxyConcurrencyTest.java \
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/AvailabilityProxyConcurrencyTest.java
 new file mode 100644
index 0000000..ed2764a
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/AvailabilityProxyConcurrencyTest.java
 @@ -0,0 +1,111 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package org.rhq.core.pc.inventory;
+
+import static org.rhq.core.domain.measurement.AvailabilityType.UP;
+
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.availability.AvailabilityFacet;
+
+@Test(enabled = false)
+public class AvailabilityProxyConcurrencyTest implements AvailabilityFacet {
+
+    private volatile int availSleepMillis;
+    private ExecutorService executor;
+    private volatile boolean interrupted;
+
+    public void testConcurrentAvailChecks() throws Exception {
+        Thread.interrupted(); // clear any hanging around interrupt status
+
+        executor = Executors.newCachedThreadPool();
+        try {
+            // our one proxy we want to call concurrently
+            final AvailabilityProxy ap = new AvailabilityProxy(this, executor, \
getClass().getClassLoader()); +
+            // prime the pump by getting the first one without problems
+            availSleepMillis = 1;
+            interrupted = false;
+            AvailabilityType firstAvail = ap.getAvailability();
+            assert UP.equals(firstAvail) : "Can't even get our first avail \
correctly: " + firstAvail; +            assert !interrupted;
+
+            // create several threads that will concurrently call getAvailability
+            availSleepMillis = 500;
+            final int numThreads = 3;
+            final Hashtable<String, AvailabilityType> availResults = new \
Hashtable<String, AvailabilityType>(numThreads); +            final Hashtable<String, \
Date> dateResults = new Hashtable<String, Date>(numThreads); +            final \
Hashtable<String, Throwable> throwableResults = new Hashtable<String, \
Throwable>(numThreads); +            final CountDownLatch startLatch = new \
CountDownLatch(1); +            final CountDownLatch endLatch = new \
CountDownLatch(numThreads); +            final Runnable runnable = new Runnable() {
+                public void run() {
+                    try {
+                        startLatch.await();
+                        AvailabilityType availCheck = ap.getAvailability();
+                        availResults.put(Thread.currentThread().getName(), \
availCheck); +                    } catch (Exception e) {
+                        throwableResults.put(Thread.currentThread().getName(), e);
+                    } finally {
+                        dateResults.put(Thread.currentThread().getName(), new \
Date()); +                        endLatch.countDown();
+                    }
+                }
+            };
+            for (int i = 0; i < numThreads; i++) {
+                Thread t = new Thread(runnable, "t" + i);
+                t.start();
+            }
+
+            // release the hounds! then wait for them to all finish
+            System.out.println("THREADS STARTED AT: " + new Date());
+            startLatch.countDown();
+            endLatch.await(10, TimeUnit.SECONDS); // should never take this long
+            System.out.println("THREADS FINISHED AT: " + new Date());
+            System.out.println("THREAD FINISH TIMES: " + dateResults);
+            System.out.println("THREADS WITH EXCEPTIONS: " + throwableResults);
+            assert !interrupted : "Why was this interrupted?";
+
+            // now make sure all of them returns UP
+            assert availResults.size() == numThreads : "Failed, bad threads: \
availResults = " + availResults; +            for (AvailabilityType availtype : \
availResults.values()) { +                assert availtype.equals(UP) : "Failed, bad \
avail: availResults = " + availResults; +            }
+        } finally {
+            executor.shutdownNow();
+        }
+    }
+
+    @Override
+    public synchronized AvailabilityType getAvailability() {
+        try {
+            Thread.sleep(availSleepMillis);
+        } catch (InterruptedException e) {
+        }
+        return UP;
+    }
+}
\ No newline at end of file


_______________________________________________
rhq-commits mailing list
rhq-commits@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/rhq-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic