You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2018/07/01 15:10:21 UTC

svn commit: r1834794 - in /uima/uima-ducc/trunk/uima-ducc-pullservice/src/test: java/org/apache/uima/ducc/ps/service/ java/org/apache/uima/ducc/ps/test/ java/org/apache/uima/ducc/ps/test/ae/ resources/

Author: cwiklik
Date: Sun Jul  1 15:10:21 2018
New Revision: 1834794

URL: http://svn.apache.org/viewvc?rev=1834794&view=rev
Log:
UIMA-5806 add junit test and supporting resources to cover AE process failure handling

Added:
    uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/
    uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/
    uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/NoOpAE.java
    uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/resources/NoOpAE.xml
Modified:
    uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java

Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java?rev=1834794&r1=1834793&r2=1834794&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java Sun Jul  1 15:10:21 2018
@@ -92,6 +92,39 @@ public class JunitPullServiceTestCase ex
 			throw e;
 		}
 	}
+	
+	@Test
+	public void testPullServiceWithProcessFailure() throws Exception {
+		int scaleout = 2;
+		super.startJetty(false);  // don't block
+		String analysisEngineDescriptor = "NoOpAE";
+		IServiceProcessor processor = new 
+				UimaServiceProcessor(analysisEngineDescriptor);
+
+		String tasURL = "http://localhost:8080/test";
+		
+		IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
+				.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
+				.withOptionalsDone().build();
+
+		try {
+			 System.setProperty("ProcessFail","true");
+			service.initialize();
+			Timer fTimer = new Timer("testPullService Timer");
+			// after 5secs stop the pull service
+			fTimer.schedule(new MyTimerTask(service, fTimer), 5000);
+			
+			service.start();
+
+		} catch (ServiceInitializationException e) {
+			throw e;
+		} catch (Exception e) {
+			throw e;
+		} finally {
+			System.getProperties().remove("ProcessFail");
+		}
+	}
+	
 	/*
 	@Test
 	public void testPullServiceBadClientURL() throws Exception {

Added: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/NoOpAE.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/NoOpAE.java?rev=1834794&view=auto
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/NoOpAE.java (added)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/test/ae/NoOpAE.java Sun Jul  1 15:10:21 2018
@@ -0,0 +1,113 @@
+/*
+ * 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.uima.ducc.ps.test.ae;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.util.Map;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.Level;
+import org.apache.uima.util.Logger;
+
+
+public class NoOpAE extends CasAnnotator_ImplBase 
+{
+    Logger logger;
+    static boolean initComplete = false;
+    String AE_Identifier = "*^^^^^^^^^ AE ";
+
+
+    @Override
+    public void initialize(UimaContext uimaContext) throws ResourceInitializationException 
+    {
+        super.initialize(uimaContext);
+
+        long tid = Thread.currentThread().getId();
+
+        Map<String, String> env = System.getenv();
+        RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
+        String pid = rmxb.getName();
+ 
+        logger = UIMAFramework.getLogger(NoOpAE.class);
+        if ( logger == null ) {
+            System.out.println("Is this nuts or what, no logger!");
+        }
+
+        if ( initComplete ) {
+            logger.log(Level.INFO, "Init bypassed in PID:TID " + pid + ":" + tid + ", already completed. ");
+            return;
+        } else {
+        	if ( logger != null )
+               logger.log(Level.INFO, "Init procedes in PID:TIDs " + pid + ":" + tid + " Environment:");
+            File workingdir = new File(System.getProperty("user.dir"));
+            File[] files = workingdir.listFiles();
+            if ( logger != null )
+               logger.log(Level.INFO, "Working directory " + workingdir.toString() + " has " + files.length + " files.");
+       }
+
+
+        if ( logger != null )
+           logger.log(Level.INFO, "^^-------> AE process " + pid + " TID " + tid + " initialization OK");
+        return;
+    }
+
+ 
+    void dolog(Object ... args)
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( Object s : args ) {
+            sb.append(s);
+            sb.append(" ");
+        }
+        String s = sb.toString();
+        System.out.println("FROM PRINTLN: " + s);
+        if ( logger != null )
+           logger.log(Level.INFO, "FROM LOGGER:" + s);
+    }
+
+    public void destroy()
+    {
+        System.out.println(AE_Identifier + " Destroy is called (0)");
+        dolog("Destroy is called (1) !");        
+        try {
+            Thread.sleep(3000);                         // simulate actual work being done here
+        } catch (InterruptedException e) {
+        }
+        System.out.println(AE_Identifier + " Destroy exits");
+    }
+
+    @Override
+    public void process(CAS cas) throws AnalysisEngineProcessException 
+    {
+    	String data = cas.getSofaDataString();
+    	if ( System.getProperty("ProcessFail") != null ) {
+    		throw new AnalysisEngineProcessException(new RuntimeException("Simulated Exception"));
+    	}
+    }
+
+ 
+}

Added: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/resources/NoOpAE.xml
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/resources/NoOpAE.xml?rev=1834794&view=auto
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/resources/NoOpAE.xml (added)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/resources/NoOpAE.xml Sun Jul  1 15:10:21 2018
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+	<!--
+	 ***************************************************************
+	 * 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.
+	 ***************************************************************
+   -->
+   
+<!-- AE that employs CAS indirection inside aggregate. -->
+
+<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
+	<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+	<primitive>true</primitive>
+	<annotatorImplementationName>org.apache.uima.ducc.ps.test.ae.NoOpAE</annotatorImplementationName>
+	<analysisEngineMetaData>
+		<name>FixedSleep Annotator</name>
+		<description>Receives CASes with modified index; does nothing (echos).</description>
+		<version>1.0</version>
+		<vendor>The Apache Software Foundation</vendor>
+		
+		<configurationParameters>
+    		<configurationParameter>
+      			<name>DebugLevel</name>
+      			<description>Debug Level</description>
+      			<type>String</type>
+      			<multiValued>false</multiValued>
+      			<mandatory>false</mandatory>
+    		</configurationParameter>
+    	</configurationParameters>
+   	 	<configurationParameterSettings>
+    	</configurationParameterSettings>
+		
+		<typeSystemDescription>
+          <imports>
+            <import name="org.apache.uima.examples.SourceDocumentInformation"/>
+          </imports>
+        </typeSystemDescription>
+		<!--
+		Capabilities: Inputs, Outputs, and Preconditions
+		-->
+		<capabilities>
+          	<capability>
+          		<inputs/>
+          		<outputs>
+          			<type allAnnotatorFeatures="true">org.apache.uima.examples.SourceDocumentInformation</type>
+          		</outputs>
+          	</capability>
+        </capabilities>
+		<operationalProperties>
+			<modifiesCas>true</modifiesCas>
+			<multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+			<outputsNewCASes>false</outputsNewCASes>
+		</operationalProperties>
+	</analysisEngineMetaData>
+</analysisEngineDescription>