Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6230 - in trunk/perfsonar-base/ls: . src/test/java/net/geant/perfsonar/ls

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6230 - in trunk/perfsonar-base/ls: . src/test/java/net/geant/perfsonar/ls


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6230 - in trunk/perfsonar-base/ls: . src/test/java/net/geant/perfsonar/ls
  • Date: Wed, 20 Mar 2013 21:51:22 +0000 (GMT)
  • Authentication-results: sfpop-ironport01.merit.edu; dkim=neutral (message not signed) header.i=none

Author: psnc.pietrzak
Date: 2013-03-20 21:51:22 +0000 (Wed, 20 Mar 2013)
New Revision: 6230

Added:

trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTestBase.java
Removed:

trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/ConfigurationFileChecker.java
Modified:
trunk/perfsonar-base/ls/pom.xml

trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSEnabledService.java

trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTest.java
Log:
Extracted sample-service project.

Modified: trunk/perfsonar-base/ls/pom.xml
===================================================================
--- trunk/perfsonar-base/ls/pom.xml 2013-03-20 21:49:14 UTC (rev 6229)
+++ trunk/perfsonar-base/ls/pom.xml 2013-03-20 21:51:22 UTC (rev 6230)
@@ -12,9 +12,9 @@
<groupId>net.geant.perfsonar.base</groupId>
<artifactId>ls</artifactId>
<version>3.0.0-SNAPSHOT</version>
- <name>perfSONAR base 3 LS client</name>
- <description>Functions to register, update and remove service
information from perfSONAR LS service</description>
- <packaging>bundle</packaging>
+ <name>perfSONAR base 3 LS client</name>
+ <description>Functions to register, update and remove service
information from perfSONAR LS service</description>
+ <packaging>bundle</packaging>

<developers>
<developer>
@@ -37,16 +37,6 @@
<artifactId>base</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>net.geant.perfsonar.base</groupId>
- <artifactId>messaging</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
-
<dependency>
<groupId>net.geant.perfsonar.base</groupId>
<artifactId>base</artifactId>
@@ -61,20 +51,19 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle</artifactId>
+ <version>2.4.2</version>
+ <type>bundle</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-bundle</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
@@ -97,6 +86,18 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-tests-artifact</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>

Deleted:
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/ConfigurationFileChecker.java
===================================================================
---
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/ConfigurationFileChecker.java
2013-03-20 21:49:14 UTC (rev 6229)
+++
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/ConfigurationFileChecker.java
2013-03-20 21:51:22 UTC (rev 6230)
@@ -1,70 +0,0 @@
-package net.geant.perfsonar.ls;
-
-import java.io.File;
-import java.io.FileInputStream;
-
-import net.geant.perfsonar.ls.LSRegistrationTask;
-import net.geant.perfsonar.messaging.Helper;
-import net.geant.perfsonar.messaging.XPathDeserializer;
-
-import org.xml.sax.InputSource;
-
-import static net.geant.perfsonar.messaging.XPathDeserializer.any;
-import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
-import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
-
-/**
- * Scheduler task that checks every second whether configuration file has
changed.
- * When it's changed it reads the configuration and injects to object model.
- *
- * @author <a
href="mailto:">Blazej
Pietrzak</a>
- */
-public class ConfigurationFileChecker implements Runnable {
-
- private File file = new File("src/test/resources/configuration.xml");
- private long lastModified = 0;
- private final LSEnabledService service;
-
- public ConfigurationFileChecker(LSEnabledService service) {
- this.service = service;
- }
-
- public void run() {
- if (!file.exists()) {
- System.err.println("Configuration file: " +
file.getAbsolutePath()
- + " is missing");
- return;
- }
-
- if (file.lastModified() > lastModified) {
- lastModified = file.lastModified();
- configureDeserialization();
- XPathDeserializer deserializer = new
XPathDeserializer();
- try {
- deserializer.deserialize(new InputSource(new
FileInputStream(file)));
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
-
- private void configureDeserialization() {
- //When configuring XPath the configurator creates a subclass
of SSHTelnetMPService that registers method invocations.
- //The instance executes base class constructor of
SSHTelnetMPService which creates this task.
- //This guard prevents calls from subclass instances forever
when configuring XPath.
- if (Helper.isConfigurationInstance(service))
- return;
-
- declarePrefix("ns",
"http://service.perfsonar.org/ns/config/base/0.9/";);
-
- try {
- whenXPath(
-
"ns:configuration/ns:service/ns:auxiliaryComponents/ns:component[@name='scheduling']/ns:actions/ns:action[@name='registration']/ns:option[@name='interval']/@value")
- .then(LSEnabledService.class,
service).setLookupServiceInterval(any(String.class));
-
- whenXPath(
-
"ns:configuration/ns:service/ns:auxiliaryComponents/ns:component[@name='scheduling']/ns:actions/ns:action[@name='registration']/ns:option[starts-with(@name,
'lsAddress')]/@value")
-
.then(LSRegistrationTask.class).addLSAddress(any(String.class));
- } catch (Exception ex) { }
- }
-}

Modified:
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSEnabledService.java
===================================================================
---
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSEnabledService.java
2013-03-20 21:49:14 UTC (rev 6229)
+++
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSEnabledService.java
2013-03-20 21:51:22 UTC (rev 6230)
@@ -2,8 +2,11 @@

import static net.geant.perfsonar.Configuration.configure;
import static
net.geant.perfsonar.ls.LSRegistrationTask.registerToLookupService;
-import net.geant.perfsonar.ls.LSRegistrationTask;
-import net.geant.perfsonar.mp.sshtelnet.SSHTelnetMPService;
+
+import javax.xml.ws.WebServiceProvider;
+
+import net.geant.perfsonar.PerfSONAR;
+import net.geant.perfsonar.ServiceType;
import net.geant.perfsonar.mp.sshtelnet.ServiceController;

/**
@@ -11,18 +14,17 @@
*
* @author <a
href="mailto:">Blazej
Pietrzak</a>
*/
-public class LSEnabledService extends SSHTelnetMPService {
- private static final int HOUR = 60 * 60;
- private static final int SECOND = 1;
+@WebServiceProvider
+public class LSEnabledService extends PerfSONAR {
+ private static final int TWO_SECONDS = 2;

private final LSRegistrationTask lsRegistrationTask = new
LSRegistrationTask(logger, this);
- private int lsInterval = HOUR;
+ private int lsInterval = TWO_SECONDS;

public LSEnabledService() {
super();

- scheduler.runEvery(HOUR, lsRegistrationTask);
- scheduler.runEvery(SECOND, new
ConfigurationFileChecker(this));
+ scheduler.runEvery(TWO_SECONDS, lsRegistrationTask);
}

static {
@@ -48,4 +50,18 @@
public synchronized int getLookupServiceInterval() {
return lsInterval;
}
+
+ @Override
+ public ServiceType getServiceType() {
+ return ServiceType.MA;
+ }
+
+ @Override
+ public String getServiceName() {
+ return "SQL";
+ }
+
+ public void setLSAddress(String address) {
+ lsRegistrationTask.addLSAddress(address);
+ }
}

Modified:
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTest.java
===================================================================
---
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTest.java
2013-03-20 21:49:14 UTC (rev 6229)
+++
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTest.java
2013-03-20 21:51:22 UTC (rev 6230)
@@ -1,52 +1,19 @@
package net.geant.perfsonar.ls;

-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import javax.xml.ws.Endpoint;
-
import net.geant.perfsonar.PerfSONAR;

-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Checks whether service registers to LS service and sends keep alive
messages.
- *
- * @author <a
href="mailto:>Blazej
Pietrzak</a>
- */
-public class LSRegisterTest {
+public class LSRegisterTest extends LSRegisterTestBase {
private static final int TWO_SECONDS = 2000;
- private MockLSService ls = new MockLSService();
-
- private PerfSONAR service = new LSEnabledService();
- private Endpoint endpoint;
-
- @Before
- public void publishServices() throws InterruptedException,
IOException {
- ls.publish("http://localhost:9000/perfsonar-ls";);
- endpoint =
Endpoint.publish("http://localhost:9000/perfsonar-java-sshtelnet-mp";,
service);
+
+ @Override
+ protected PerfSONAR givenService() {
+ LSEnabledService result = new LSEnabledService();
+ ((LSEnabledService) result).setLSAddress(MOCK_LS_URL);
+ return result;
}
-
- @After
- public void stopServices() {
- endpoint.stop();
- service.stop();
- ls.stop();
- endpoint = null;
- ls = null;
- service = null;
- }

- @Test
- public void shouldRegisterToLookupService() throws Exception {
- Thread.sleep(TWO_SECONDS * 3 + 500);
- assertEquals(1, ls.getRegisterCount());
- assertTrue(
- "Keep alive should be sent at least 3x but was "
- + ls.getKeepAliveCount(),
ls.getKeepAliveCount() >= 2);
+ @Override
+ protected int getLSInterval() {
+ return TWO_SECONDS;
}
}

Copied:
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTestBase.java
(from rev 6179,
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTest.java)
===================================================================
---
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTestBase.java
(rev 0)
+++
trunk/perfsonar-base/ls/src/test/java/net/geant/perfsonar/ls/LSRegisterTestBase.java
2013-03-20 21:51:22 UTC (rev 6230)
@@ -0,0 +1,56 @@
+package net.geant.perfsonar.ls;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import javax.xml.ws.Endpoint;
+
+import net.geant.perfsonar.PerfSONAR;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Checks whether service registers to LS service and sends keep alive
messages.
+ *
+ * @author <a
href="mailto:>Blazej
Pietrzak</a>
+ */
+public abstract class LSRegisterTestBase {
+ protected static final String MOCK_LS_URL =
"http://localhost:9000/perfsonar-ls";;
+ private MockLSService ls = new MockLSService();
+
+ private PerfSONAR service;
+ private Endpoint endpoint;
+
+ @Before
+ public void publishServices() throws InterruptedException,
IOException {
+ ls.publish("http://localhost:9000/perfsonar-ls";);
+ service = givenService();
+ endpoint =
Endpoint.publish("http://localhost:9000/perfsonar-java-sshtelnet-mp";,
service);
+ }
+
+ protected abstract PerfSONAR givenService();
+ protected abstract int getLSInterval();
+
+ @After
+ public void stopServices() {
+ endpoint.stop();
+ service.stop();
+ ls.stop();
+ endpoint = null;
+ ls = null;
+ service = null;
+ }
+
+ @Test
+ public void shouldRegisterToLookupService() throws Exception {
+ Thread.sleep(getLSInterval() * 3 + 500);
+ assertEquals(1, ls.getRegisterCount());
+ assertTrue(
+ "Keep alive should be sent at least 2x but was "
+ + ls.getKeepAliveCount(),
ls.getKeepAliveCount() >= 2);
+ }
+}



  • [pS-dev] [GEANT/SA2/ps-java-services] r6230 - in trunk/perfsonar-base/ls: . src/test/java/net/geant/perfsonar/ls, svn-noreply, 03/20/2013

Archive powered by MHonArc 2.6.16.

Top of Page