Issue 93: moved concurrent libraries to their own module and setup custom properties so that it can compile under jdk 5

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1885 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-09-23 22:50:18 +00:00
parent 30a738b327
commit ed12a262ce
10 changed files with 214 additions and 6 deletions

112
concurrent/pom.xml Executable file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
$HeadURL$
$Revision$
$Date$
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>jclouds-project</artifactId>
<groupId>org.jclouds</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jclouds-concurrent</artifactId>
<name>jclouds concurrent</name>
<packaging>jar</packaging>
<description>Core components to access jclouds services</description>
<scm>
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/concurrent</connection>
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/concurrent</developerConnection>
<url>http://jclouds.googlecode.com/svn/trunk/concurrent</url>
</scm>
<properties>
<jclouds.test.listener />
</properties>
<dependencies>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0-rc2</version>
</dependency>
</dependencies>
<profiles>
<profile>
<!-- http://code.google.com/p/jclouds/issues/detail?id=93 -->
<id>compilejdk6executors</id>
<activation>
<jdk>1.5</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>java.concurrent</groupId>
<artifactId>jdk6-exec</artifactId>
<version>6.18</version>
<outputDirectory>${project.build.directory}/endorsed</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Djava.endorsed.dirs=${project.build.directory}/endorsed</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argline>-Djava.endorsed.dirs=${project.build.directory}/endorsed</argline>
<properties>
<property>
<name>listener</name>
<value />
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -59,7 +59,8 @@ public class WithinThreadExecutorService extends WithinThreadExecutor implements
/**
* {@inheritDoc}
*/
public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks) throws InterruptedException {
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
checkState(!shutdown, "shutdown!");
List<Future<T>> results = new ArrayList<Future<T>>(tasks.size());
for (Callable<T> task : tasks) {
@ -74,8 +75,8 @@ public class WithinThreadExecutorService extends WithinThreadExecutor implements
/**
* {@inheritDoc}
*/
public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException {
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
TimeUnit unit) throws InterruptedException {
checkState(!shutdown, "shutdown!");
List<Future<T>> results = new ArrayList<Future<T>>(tasks.size());
long timeUp = System.nanoTime() + unit.toNanos(timeout);
@ -94,7 +95,7 @@ public class WithinThreadExecutorService extends WithinThreadExecutor implements
/**
* {@inheritDoc}
*/
public <T> T invokeAny(Collection<Callable<T>> tasks) throws InterruptedException,
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException,
ExecutionException {
checkState(!shutdown, "shutdown!");
checkArgument(tasks.size() > 0, "no tasks");
@ -115,7 +116,7 @@ public class WithinThreadExecutorService extends WithinThreadExecutor implements
/**
* {@inheritDoc}
*/
public <T> T invokeAny(Collection<Callable<T>> tasks, long timeout, TimeUnit unit)
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
checkState(!shutdown, "shutdown!");
checkArgument(tasks.size() > 0, "no tasks");

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.concurrent;
import static org.testng.Assert.assertEquals;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.testng.annotations.Test;
import com.google.common.base.Function;
/**
* Tests behavior of FutureExceptionParser
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "concurrent.FutureExceptionParserTest")
public class FutureExceptionParserTest {
ExecutorService executorService = new WithinThreadExecutorService();
@Test
public void testGet() throws InterruptedException, ExecutionException {
Future<?> future = createFuture(new RuntimeException("foo"));
assertEquals(future.get(), "foo");
}
@Test(expectedExceptions = ExecutionException.class)
public void testGetUnmatched() throws InterruptedException, ExecutionException {
Future<?> future = createFuture(new Exception("foo"));
assertEquals(future.get(), "foo");
}
@Test
public void testGetLongTimeUnit() throws InterruptedException, ExecutionException,
TimeoutException {
Future<?> future = createFuture(new RuntimeException("foo"));
assertEquals(future.get(1, TimeUnit.SECONDS), "foo");
}
@Test(expectedExceptions = ExecutionException.class)
public void testGetLongTimeUnitUnmatched() throws InterruptedException, ExecutionException,
TimeoutException {
Future<?> future = createFuture(new Exception("foo"));
assertEquals(future.get(1, TimeUnit.SECONDS), "foo");
}
@SuppressWarnings("unchecked")
private Future<?> createFuture(final Exception exception) {
Future<?> future = executorService.submit(new Callable<String>() {
public String call() throws Exception {
throw exception;
}
});
future = new FutureExceptionParser(future, new Function<Exception, String>() {
public String apply(Exception from) {
return (from instanceof RuntimeException) ? from.getMessage() : null;
}
});
return future;
}
}

View File

@ -144,6 +144,7 @@
<maven.compile.target>1.5</maven.compile.target>
<maven.compile.optimize>true</maven.compile.optimize>
<maven.compile.deprecation>true</maven.compile.deprecation>
<jclouds.test.listener>org.jclouds.test.testng.UnitTestStatusListener</jclouds.test.listener>
</properties>
<dependencies>
@ -205,7 +206,7 @@
<properties>
<property>
<name>listener</name>
<value>org.jclouds.test.testng.UnitTestStatusListener</value>
<value>${jclouds.test.listener}</value>
</property>
</properties>
</configuration>