Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5380 - in trunk/ps-mdm-lsclient-impl/src: main/java/org/perfsonar/ri/lsclient/level1 main/java/org/perfsonar/ri/lsclient/utils test/java/org/perfsonar/ri/lsclient/utils

Subject: perfsonar development work

List archive

perfsonar: r5380 - in trunk/ps-mdm-lsclient-impl/src: main/java/org/perfsonar/ri/lsclient/level1 main/java/org/perfsonar/ri/lsclient/utils test/java/org/perfsonar/ri/lsclient/utils


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5380 - in trunk/ps-mdm-lsclient-impl/src: main/java/org/perfsonar/ri/lsclient/level1 main/java/org/perfsonar/ri/lsclient/utils test/java/org/perfsonar/ri/lsclient/utils
  • Date: Mon, 7 Dec 2009 10:41:53 -0500

Author: krzjed
Date: 2009-12-07 10:41:53 -0500 (Mon, 07 Dec 2009)
New Revision: 5380

Added:

trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/SortedResultCollectorTest.java
Modified:

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultCollector.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/SortedResultCollector.java

trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultCollectorTest.java

trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultContainerTest.java
Log:
unit tests for SortedResultCollector

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -113,6 +113,9 @@
logger.warn(e);
} catch (IOException e) {
logger.warn(e);
+ } catch (InterruptedException e) {
+ // should not occur
+ logger.warn(e);
}
return new DiscoveryStepImpl(new LsQueryException("None of the root
lookupservices could be consulted"));
}

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -63,8 +63,12 @@
}

data.clear();
- logger.info("gLS' added " + collector.getValues());
- data.addAll(collector.getValues());
+ try {
+ logger.info("gLS' added " + collector.getValues());
+ data.addAll(collector.getValues());
+ } catch (InterruptedException e) {
+ logger.error(e);
+ }
}

public synchronized Iterator<LookupService> iterator() {

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultCollector.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultCollector.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultCollector.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -7,7 +7,7 @@
import org.apache.log4j.Logger;

public class ResultCollector<T> {
- private Logger logger = Logger.getLogger(ResultCollector.class);
+ private static Logger logger = Logger.getLogger(ResultCollector.class);
private int required;
private Set<T> resultSet = new HashSet<T>();

@@ -23,21 +23,19 @@
this.resultSet.add(element);
this.required--;
this.testRequirements();
+ logger.info(element + " addet to ResultCollector");
}

public synchronized void addAllElements(Collection<? extends T> element)
{
this.resultSet.addAll(element);
this.required--;
this.testRequirements();
+ logger.info(element + " addet to ResultCollector");
}

- public synchronized Set<T> getResultSet() {
+ public synchronized Set<T> getResultSet() throws InterruptedException {
while (required > 0) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.error(e);
- }
+ this.wait();
}
return this.resultSet;
}

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -5,15 +5,11 @@
public class ResultContainer<T> {
private T value;
private boolean valueSet = false;
- private Logger logger = Logger.getLogger(ResultContainer.class);
+ private static Logger logger = Logger.getLogger(ResultContainer.class);

- public synchronized T getValue() {
+ public synchronized T getValue() throws InterruptedException {
while (!this.valueSet) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.error(e);
- }
+ this.wait();
}
return this.value;
}
@@ -22,6 +18,7 @@
if (!this.valueSet) {
this.value = value;
this.valueSet = true;
+ logger.info(value + " set at the ResultContainer");
this.notifyAll();
}
}

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/SortedResultCollector.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/SortedResultCollector.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/SortedResultCollector.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -8,7 +8,7 @@
import org.apache.log4j.Logger;

public class SortedResultCollector<K, V> {
- private Logger logger = Logger.getLogger(ResultCollector.class);
+ private static Logger logger = Logger.getLogger(ResultCollector.class);
private int required;
private SortedMap<K, V> resultMap = new TreeMap<K, V>();

@@ -32,24 +32,16 @@
this.testRequirements();
}

- public synchronized SortedMap<K, V> getResultMap() {
+ public synchronized SortedMap<K, V> getResultMap() throws
InterruptedException {
while (required > 0) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.error(e);
- }
+ this.wait();
}
return this.resultMap;
}

- public synchronized Collection<V> getValues() {
+ public synchronized Collection<V> getValues() throws
InterruptedException {
while (required > 0) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.error(e);
- }
+ this.wait();
}
return this.resultMap.values();
}

Modified:
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultCollectorTest.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultCollectorTest.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultCollectorTest.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -16,8 +16,8 @@
this.rc = new ResultCollector<Integer>();
}

- @Test(timeout = 10)
- public void addSingleElementTest() {
+ @Test(timeout = 100)
+ public void addSingleElementTest() throws InterruptedException {
this.rc.signalMoreElements();
this.rc.addElement(2);
Set<Integer> res = rc.getResultSet();
@@ -25,8 +25,8 @@
Assert.assertTrue(res.contains(2));
}

- @Test(timeout = 10)
- public void addManyElementTest() {
+ @Test(timeout = 100)
+ public void addManyElementTest() throws InterruptedException {
this.rc = new ResultCollector<Integer>(3);
this.rc.signalMoreElements();
this.rc.addElement(2);
@@ -40,8 +40,15 @@
Assert.assertTrue(res.contains(4));
}

- @Test(timeout = 10)
- public void addCollectionElementTest() {
+ @Test(timeout = 100, expected = InterruptedException.class)
+ public void waitTest() throws InterruptedException {
+ this.rc.signalMoreElements();
+ rc.getResultSet();
+ Assert.fail();
+ }
+
+ @Test(timeout = 100)
+ public void addCollectionElementTest() throws InterruptedException {
this.rc = new ResultCollector<Integer>(3);
this.rc.addElement(2);
Collection<Integer> c = new HashSet<Integer>();
@@ -56,8 +63,8 @@
Assert.assertTrue(res.contains(4));
}

- @Test(timeout = 50)
- public void MultiThreadTest() {
+ @Test(timeout = 100)
+ public void MultiThreadTest() throws InterruptedException {
int noOfThreads = 10;
this.rc = new ResultCollector<Integer>(noOfThreads);
for (int i = 0; i < noOfThreads; i++) {
@@ -77,7 +84,7 @@
}
}

- @Test(timeout = 10)
+ @Test(timeout = 100)
public void emptyTest() throws InterruptedException {
this.rc.signalMoreElements();
this.rc.signalLackOfElement();

Modified:
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultContainerTest.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultContainerTest.java
2009-12-07 13:46:42 UTC (rev 5379)
+++
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/ResultContainerTest.java
2009-12-07 15:41:53 UTC (rev 5380)
@@ -13,14 +13,14 @@
}

@Test
- public void basicTest() {
+ public void basicTest() throws InterruptedException {
rc.setValue(2);
rc.setValue(3);
Assert.assertEquals("Value returned different than set first.", 2,
rc.getValue());
}

@Test
- public void multiThreadTest() {
+ public void multiThreadTest() throws InterruptedException {
final int noOThreads = 10;
final ResultContainer<Integer> rc = new ResultContainer<Integer>();
for (int i = 0; i < noOThreads; i++) {
@@ -46,4 +46,10 @@
}
Assert.assertEquals("Value returned different than set by the
fastest thread.", 0, rc.getValue());
}
+
+ @Test(timeout = 100, expected = InterruptedException.class)
+ public void waitTest() throws InterruptedException {
+ rc.getValue();
+ Assert.fail();
+ }
}

Added:
trunk/ps-mdm-lsclient-impl/src/test/java/org/perfsonar/ri/lsclient/utils/SortedResultCollectorTest.java



  • perfsonar: r5380 - in trunk/ps-mdm-lsclient-impl/src: main/java/org/perfsonar/ri/lsclient/level1 main/java/org/perfsonar/ri/lsclient/utils test/java/org/perfsonar/ri/lsclient/utils, svnlog, 12/07/2009

Archive powered by MHonArc 2.6.16.

Top of Page