nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marka...@apache.org
Subject [04/47] incubator-nifi git commit: NIFI-268: Fail any unit test that uses a Processor that uses deprecated annotations
Date Mon, 26 Jan 2015 14:16:20 GMT
NIFI-268: Fail any unit test that uses a Processor that uses deprecated annotations


Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/29b3ad89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/29b3ad89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/29b3ad89

Branch: refs/heads/develop
Commit: 29b3ad89a46b6301e28e158e37edfe0bee808978
Parents: 1c0eb6c
Author: Mark Payne <markap14@hotmail.com>
Authored: Thu Jan 15 15:15:24 2015 -0500
Committer: Mark Payne <markap14@hotmail.com>
Committed: Fri Jan 16 12:05:32 2015 -0500

----------------------------------------------------------------------
 .../util/TestStandardProcessorTestRunner.java   | 86 ++++++++++++++++++++
 .../apache/nifi/util/MockProcessSession.java    |  1 -
 .../nifi/util/StandardProcessorTestRunner.java  | 63 ++++++++++++--
 3 files changed, 142 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/29b3ad89/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
----------------------------------------------------------------------
diff --git a/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
new file mode 100644
index 0000000..37bcf23
--- /dev/null
+++ b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
@@ -0,0 +1,86 @@
+/*
+ * 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.apache.nifi.util;
+
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.junit.Test;
+
+public class TestStandardProcessorTestRunner {
+
+    @Test(expected=AssertionError.class)
+    public void testFailOnDeprecatedTypeAnnotation() {
+        new StandardProcessorTestRunner(new DeprecatedAnnotation());
+    }
+    
+    @Test
+    public void testDoesNotFailOnNonDeprecatedTypeAnnotation() {
+        new StandardProcessorTestRunner(new NewAnnotation());
+    }
+    
+    @Test(expected=AssertionError.class)
+    public void testFailOnDeprecatedMethodAnnotation() {
+        new StandardProcessorTestRunner(new DeprecatedMethodAnnotation());
+    }
+    
+    @Test
+    public void testDoesNotFailOnNonDeprecatedMethodAnnotation() {
+        new StandardProcessorTestRunner(new NewMethodAnnotation());
+    }
+
+    
+    
+    @SuppressWarnings("deprecation")
+    @org.apache.nifi.processor.annotation.Tags({"deprecated"})
+    private static class DeprecatedAnnotation extends AbstractProcessor {
+        @Override
+        public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
+        }
+    }
+    
+    @org.apache.nifi.annotation.documentation.Tags({"deprecated"})
+    private static class NewAnnotation extends AbstractProcessor {
+        @Override
+        public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
+        }
+    }
+    
+    private static class NewMethodAnnotation extends AbstractProcessor {
+        @org.apache.nifi.annotation.lifecycle.OnScheduled
+        public void dummy() {
+            
+        }
+        
+        @Override
+        public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
+        }
+    }
+    
+    private static class DeprecatedMethodAnnotation extends AbstractProcessor {
+        @SuppressWarnings("deprecation")
+        @org.apache.nifi.processor.annotation.OnScheduled
+        public void dummy() {
+            
+        }
+        
+        @Override
+        public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/29b3ad89/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
index ea55b34..83c75c6 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
@@ -786,7 +786,6 @@ public class MockProcessSession implements ProcessSession {
      * @param sources
      */
     private FlowFile inheritAttributes(final Collection<FlowFile> sources, final FlowFile
destination) {
-        final String uuid = destination.getAttribute(CoreAttributes.UUID.key());
         final StringBuilder parentUuidBuilder = new StringBuilder();
         int uuidsCaptured = 0;
         for (final FlowFile source : sources) {

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/29b3ad89/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
index 40d5035..d0ecd52 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
@@ -21,7 +21,9 @@ import static java.util.Objects.requireNonNull;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
@@ -39,6 +41,12 @@ import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.nifi.annotation.behavior.TriggerSerially;
+import org.apache.nifi.annotation.lifecycle.OnAdded;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnShutdown;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationResult;
@@ -50,15 +58,8 @@ import org.apache.nifi.processor.ProcessSessionFactory;
 import org.apache.nifi.processor.Processor;
 import org.apache.nifi.processor.QueueSize;
 import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.processor.annotation.OnAdded;
-import org.apache.nifi.processor.annotation.OnScheduled;
-import org.apache.nifi.processor.annotation.OnShutdown;
-import org.apache.nifi.processor.annotation.OnStopped;
-import org.apache.nifi.processor.annotation.OnUnscheduled;
-import org.apache.nifi.processor.annotation.TriggerSerially;
 import org.apache.nifi.provenance.ProvenanceReporter;
 import org.apache.nifi.reporting.InitializationException;
-
 import org.junit.Assert;
 
 public class StandardProcessorTestRunner implements TestRunner {
@@ -74,6 +75,16 @@ public class StandardProcessorTestRunner implements TestRunner {
     private int numThreads = 1;
     private final AtomicInteger invocations = new AtomicInteger(0);
 
+    private static final Set<Class<? extends Annotation>> deprecatedTypeAnnotations
= new HashSet<>();
+    private static final Set<Class<? extends Annotation>> deprecatedMethodAnnotations
= new HashSet<>();
+    
+    static {
+        // do this in a separate method, just so that we can add a @SuppressWarnings annotation
+        // because we want to indicate explicitly that we know that we are using deprecated
+        // classes here.
+        populateDeprecatedMethods();
+    }
+    
     StandardProcessorTestRunner(final Processor processor) {
         this.processor = processor;
         this.idGenerator = new AtomicLong(0L);
@@ -82,6 +93,8 @@ public class StandardProcessorTestRunner implements TestRunner {
         this.sessionFactory = new MockSessionFactory(sharedState);
         this.context = new MockProcessContext(processor);
 
+        detectDeprecatedAnnotations(processor);
+        
         final MockProcessorInitializationContext mockInitContext = new MockProcessorInitializationContext(processor,
context);
         processor.initialize(mockInitContext);
 
@@ -94,6 +107,42 @@ public class StandardProcessorTestRunner implements TestRunner {
         triggerSerially = null != processor.getClass().getAnnotation(TriggerSerially.class);
     }
 
+    @SuppressWarnings("deprecation")
+    private static void populateDeprecatedMethods() {
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.CapabilityDescription.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.EventDriven.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.SideEffectFree.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.SupportsBatching.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.Tags.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerWhenEmpty.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerWhenAnyDestinationAvailable.class);
+        deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerSerially.class);
+        
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnRemoved.class);
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnAdded.class);
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnScheduled.class);
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnShutdown.class);
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnStopped.class);
+        deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnUnscheduled.class);
+    }
+    
+    private static void detectDeprecatedAnnotations(final Processor processor) {
+        for ( final Class<? extends Annotation> annotationClass : deprecatedTypeAnnotations
) {
+            if ( processor.getClass().isAnnotationPresent(annotationClass) ) {
+                Assert.fail("Processor is using deprecated Annotation " + annotationClass.getCanonicalName());
+            }
+        }
+        
+        for ( final Class<? extends Annotation> annotationClass : deprecatedMethodAnnotations
) {
+            for ( final Method method : processor.getClass().getMethods() ) {
+                if ( method.isAnnotationPresent(annotationClass) ) {
+                    Assert.fail("Processor is using deprecated Annotation " + annotationClass.getCanonicalName()
+ " for method " + method);
+                }
+            }
+        }
+        
+    }
+    
     @Override
     public void setValidateExpressionUsage(final boolean validate) {
         context.setValidateExpressionUsage(validate);


Mime
View raw message