Skip to content
Browse files

Restored platform test compatibility with Cascading 2.0.x via return …

…of c.p.PlatformRunner.Platform annotation and deprecated c.t.LocalPlatform and c.t.HadoopPlatform platform implementations.
  • Loading branch information...
1 parent ebf1191 commit d3e3bdd3096ef9b645c654012f172407825fbf29 @cwensel cwensel committed Feb 11, 2013
View
3 CHANGES.txt
@@ -2,6 +2,9 @@ Cascading Change Log
2.1.4 [unreleased]
+ Restored platform test compatibility with Cascading 2.0.x via return of c.p.PlatformRunner.Platform annotation
+ and deprecated c.t.LocalPlatform and c.t.HadoopPlatform platform implementations.
+
2.1.3
Fix for extra trailing ']' in c.t.Tap#toString().
View
29 cascading-hadoop/src/test/java/cascading/test/HadoopPlatform.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007-2013 Concurrent, Inc. All Rights Reserved.
+ *
+ * Project and contact information: http://www.cascading.org/
+ *
+ * This file is part of the Cascading project.
+ *
+ * Licensed 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 cascading.test;
+
+/**
+ * Retained for backwards compatibility. See {@link cascading.platform.hadoop.HadoopPlatform}.
+ */
+@Deprecated
+public class HadoopPlatform extends cascading.platform.hadoop.HadoopPlatform
+ {
+ }
View
29 cascading-local/src/test/java/cascading/test/LocalPlatform.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007-2013 Concurrent, Inc. All Rights Reserved.
+ *
+ * Project and contact information: http://www.cascading.org/
+ *
+ * This file is part of the Cascading project.
+ *
+ * Licensed 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 cascading.test;
+
+/**
+ * Retained for backwards compatibility. See {@link cascading.platform.local.LocalPlatform}.
+ */
+@Deprecated
+public class LocalPlatform extends cascading.platform.local.LocalPlatform
+ {
+ }
View
49 cascading-platform/src/test/java/cascading/platform/PlatformRunner.java
@@ -22,11 +22,16 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
@@ -63,6 +68,12 @@
private List<Runner> runners;
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Platform
+ {
+ Class<? extends TestPlatform>[] value();
+ }
+
public PlatformRunner( Class<PlatformTestCase> testClass ) throws Throwable
{
super( testClass );
@@ -102,20 +113,39 @@ public static TestPlatform makeInstance( Class<? extends TestPlatform> type )
runners = new ArrayList<Runner>();
- Set<Class<? extends TestPlatform>> classes = getPlatformClass( javaClass.getClassLoader() );
+ // test for use of annotation
+ Set<Class<? extends TestPlatform>> classes = getPlatformClassesFromAnnotation( javaClass );
+
+ // if no platforms declared from the annotation, test classpath
+ if( classes.isEmpty() )
+ classes = getPlatformClassesFromClasspath( javaClass.getClassLoader() );
for( Class<? extends TestPlatform> platformClass : classes )
addPlatform( javaClass, platformClass );
return runners;
}
- public static Set<Class<? extends TestPlatform>> getPlatformClass( ClassLoader classLoader ) throws IOException, ClassNotFoundException
+ private Set<Class<? extends TestPlatform>> getPlatformClassesFromAnnotation( Class<?> javaClass ) throws Throwable
+ {
+ PlatformRunner.Platform annotation = javaClass.getAnnotation( PlatformRunner.Platform.class );
+
+ if( annotation == null )
+ return Collections.EMPTY_SET;
+
+ HashSet<Class<? extends TestPlatform>> classes = new LinkedHashSet<Class<? extends TestPlatform>>( Arrays.asList( annotation.value() ) );
+
+ LOG.info( "found {} test platforms from Platform annotation", classes.size() );
+
+ return classes;
+ }
+
+ protected static Set<Class<? extends TestPlatform>> getPlatformClassesFromClasspath( ClassLoader classLoader ) throws IOException, ClassNotFoundException
{
- Set<Class<? extends TestPlatform>> classes = new HashSet<Class<? extends TestPlatform>>();
+ Set<Class<? extends TestPlatform>> classes = new LinkedHashSet<Class<? extends TestPlatform>>();
Properties properties = new Properties();
- LOG.info( "classloader: {}", classLoader );
+ LOG.debug( "classloader: {}", classLoader );
Enumeration<URL> urls = classLoader.getResources( PLATFORM_RESOURCE );
@@ -125,6 +155,17 @@ public static TestPlatform makeInstance( Class<? extends TestPlatform> type )
classes.add( (Class<? extends TestPlatform>) getPlatformClass( classLoader, properties, stream ) );
}
+ if( classes.isEmpty() )
+ {
+ LOG.warn( "no platform tests will be run" );
+ LOG.warn( "did not find {} in the classpath, no {} instances found", PLATFORM_RESOURCE, TestPlatform.class.getCanonicalName() );
+ LOG.warn( "add cascading-local, cascading-hadoop, and/or external planner library to the test classpath" );
+ }
+ else
+ {
+ LOG.info( "found {} test platforms from classpath", classes.size() );
+ }
+
return classes;
}
View
35 cascading-platform/src/test/java/cascading/test/PlatformRunner.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007-2013 Concurrent, Inc. All Rights Reserved.
+ *
+ * Project and contact information: http://www.cascading.org/
+ *
+ * This file is part of the Cascading project.
+ *
+ * Licensed 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 cascading.test;
+
+import cascading.PlatformTestCase;
+
+/**
+ * Retained for backwards compatibility. See {@link cascading.platform.PlatformRunner}.
+ */
+@Deprecated
+public class PlatformRunner extends cascading.platform.PlatformRunner
+ {
+ public PlatformRunner( Class<PlatformTestCase> testClass ) throws Throwable
+ {
+ super( testClass );
+ }
+ }

0 comments on commit d3e3bdd

Please sign in to comment.
Something went wrong with that request. Please try again.