eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-402] Fix test app unit test suites
Date Thu, 04 Aug 2016 03:21:07 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop 89a5bcca7 -> 6f8b82ef0


[EAGLE-402] Fix test app unit test suites

Author: Hao Chen <hao@apache.org>

Closes #298 from haoch/FixTestApp.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/6f8b82ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/6f8b82ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/6f8b82ef

Branch: refs/heads/develop
Commit: 6f8b82ef0d0f5d2597f0ec4549c0cce3ca5fec54
Parents: 89a5bcc
Author: Hao Chen <hao@apache.org>
Authored: Thu Aug 4 11:20:54 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Thu Aug 4 11:20:54 2016 +0800

----------------------------------------------------------------------
 .../app/spi/AbstractApplicationProvider.java    | 11 ---
 .../eagle/app/TestApplicationTestSuite.java     | 77 ------------------
 .../apache/eagle/app/TestStormApplication.java  | 82 ++++++++++++++++++++
 .../app/storm/MockStormApplicationTest.java     |  2 +-
 ...org.apache.eagle.app.spi.ApplicationProvider |  2 +-
 .../test/resources/TestApplicationMetadata.xml  |  2 +-
 .../src/test/resources/providers.xml            |  2 +-
 7 files changed, 86 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
index c451550..20816db 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
@@ -72,17 +72,6 @@ public abstract class AbstractApplicationProvider<T extends Application>
impleme
     @Override
     public void prepare(ApplicationProviderConfig providerConfig, Config envConfig) {
         this.applicationDesc.setJarPath(providerConfig.getJarPath());
-//        String sinkClassName = envConfig.hasPath(APPLICATIONS_SINK_TYPE_PROPS_KEY) ?
-//                envConfig.getString(APPLICATIONS_SINK_TYPE_PROPS_KEY) : DEFAULT_APPLICATIONS_SINK_TYPE;
-//        try {
-//            Class<?> sinkClass = Class.forName(sinkClassName);
-//            if(!StreamSink.class.isAssignableFrom(sinkClass)){
-//                throw new IllegalStateException(sinkClassName+ "is not assignable from
"+StreamSink.class.getCanonicalName());
-//            }
-//            applicationDesc.setSinkClass(sinkClass);
-//        } catch (ClassNotFoundException e) {
-//            throw new IllegalStateException(e.getMessage(),e.getCause());
-//        }
     }
 
     protected void setVersion(String version) {

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestApplicationTestSuite.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestApplicationTestSuite.java
b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestApplicationTestSuite.java
deleted file mode 100644
index d318abb..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestApplicationTestSuite.java
+++ /dev/null
@@ -1,77 +0,0 @@
-///*
-// * 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
-// * <p/>
-// * http://www.apache.org/licenses/LICENSE-2.0
-// * <p/>
-// * 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.eagle.app;
-//
-//import com.google.inject.Inject;
-//import org.apache.eagle.app.resource.ApplicationResource;
-//import org.apache.eagle.app.service.ApplicationOperations;
-//import org.apache.eagle.app.test.ServerSimulator;
-//import org.apache.eagle.app.test.AppUnitTestRunner;
-//import org.apache.eagle.metadata.model.ApplicationDesc;
-//import org.apache.eagle.metadata.model.ApplicationEntity;
-//import org.apache.eagle.metadata.model.SiteEntity;
-//import org.apache.eagle.metadata.resource.SiteResource;
-//import org.junit.Assert;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//
-//import java.util.Collection;
-//
-//@RunWith(AppUnitTestRunner.class)
-//public class TestApplicationTestSuite {
-//    @Inject private SiteResource siteResource;
-//    @Inject private ApplicationResource applicationResource;
-//    @Inject private ServerSimulator simulator;
-//
-//    @Test
-//    public void testApplicationProviderLoading(){
-//        Collection<ApplicationDesc> applicationDescs = applicationResource.getApplicationDescs().getData();
-//        Assert.assertNotNull(applicationDescs);
-//        Assert.assertEquals(1,applicationDescs.size());
-//    }
-//
-//    @Test
-//    public void testApplicationLifecycle() throws InterruptedException {
-//        // Create local site
-//        SiteEntity siteEntity = new SiteEntity();
-//        siteEntity.setSiteId("test_site");
-//        siteEntity.setSiteName("Test Site");
-//        siteEntity.setDescription("Test Site for ExampleApplicationTest");
-//        siteResource.createSite(siteEntity);
-//        Assert.assertNotNull(siteEntity.getUuid());
-//
-//        // Install application
-//        ApplicationEntity applicationEntity = applicationResource.installApplication(new
ApplicationOperations.InstallOperation("test_site","TEST_APPLICATION", ApplicationEntity.Mode.LOCAL)).getData();
-//        // Start application
-//        applicationResource.startApplication(new ApplicationOperations.StartOperation(applicationEntity.getUuid()));
-//        // Stop application
-//        applicationResource.stopApplication(new ApplicationOperations.StopOperation(applicationEntity.getUuid()));
-//        // Uninstall application
-//        applicationResource.uninstallApplication(new ApplicationOperations.UninstallOperation(applicationEntity.getUuid()));
-//        try {
-//            applicationResource.getApplicationEntityByUUID(applicationEntity.getUuid());
-//            Assert.fail("Application instance (UUID: "+applicationEntity.getUuid()+") should
have been uninstalled");
-//        } catch (Exception ex){
-//            // Expected exception
-//        }
-//    }
-//
-//    @Test
-//    public void testApplicationQuickRunWithAppType(){
-//        simulator.start("TEST_APPLICATION");
-//    }
-//}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
new file mode 100644
index 0000000..6585564
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
@@ -0,0 +1,82 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app;
+
+import backtype.storm.generated.StormTopology;
+import backtype.storm.spout.SpoutOutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.topology.TopologyBuilder;
+import backtype.storm.topology.base.BaseRichSpout;
+import backtype.storm.tuple.Fields;
+import org.apache.eagle.app.environment.impl.StormEnvironment;
+import org.apache.eagle.app.spi.AbstractApplicationProvider;
+
+import java.util.Arrays;
+import java.util.Map;
+
+public class TestStormApplication extends StormApplication<TestStormApplication.TestStormAppConfig>{
+    @Override
+    public StormTopology execute(TestStormAppConfig config, StormEnvironment environment)
{
+        TopologyBuilder builder = new TopologyBuilder();
+        builder.setSpout("metric_spout", new RandomEventSpout(), config.getSpoutNum());
+        builder.setBolt("sink_1",environment.getFlattenStreamSink("TEST_STREAM_1",config)).fieldsGrouping("metric_spout",new
Fields("metric"));
+        builder.setBolt("sink_2",environment.getFlattenStreamSink("TEST_STREAM_2",config)).fieldsGrouping("metric_spout",new
Fields("metric"));
+        return builder.createTopology();
+    }
+
+    public final static class TestStormAppConfig extends Configuration{
+        private int spoutNum = 1;
+
+        public int getSpoutNum() {
+            return spoutNum;
+        }
+
+        public void setSpoutNum(int spoutNum) {
+            this.spoutNum = spoutNum;
+        }
+    }
+
+    private class RandomEventSpout extends BaseRichSpout {
+        private SpoutOutputCollector _collector;
+        @Override
+        public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector)
{
+            _collector = spoutOutputCollector;
+        }
+
+        @Override
+        public void nextTuple() {
+            _collector.emit(Arrays.asList("disk.usage",System.currentTimeMillis(),"host_1",56.7));
+            _collector.emit(Arrays.asList("cpu.usage",System.currentTimeMillis(),"host_2",99.8));
+        }
+
+        @Override
+        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
+            outputFieldsDeclarer.declare(new Fields("metric","timestamp","source","value"));
+        }
+    }
+
+    public final static class Provider extends AbstractApplicationProvider<TestStormApplication>
{
+        public Provider(){
+            super("TestApplicationMetadata.xml");
+        }
+        @Override
+        public TestStormApplication getApplication() {
+            return new TestStormApplication();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplicationTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplicationTest.java
b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplicationTest.java
index 77bc113..5536c40 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplicationTest.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplicationTest.java
@@ -71,6 +71,6 @@ public class MockStormApplicationTest {
         appConfig.setLoaded(true);
         appConfig.setSpoutNum(4);
         new MockStormApplication().run(appConfig);
-        Thread.sleep(Long.MAX_VALUE);
+//        Thread.sleep(Long.MAX_VALUE);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
b/eagle-core/eagle-app/eagle-app-base/src/test/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
index fa18007..2ff0092 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
@@ -13,4 +13,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-org.apache.eagle.app.TestStormAppImpl$Provider
\ No newline at end of file
+org.apache.eagle.app.TestStormApplication$Provider
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/resources/TestApplicationMetadata.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/resources/TestApplicationMetadata.xml
b/eagle-core/eagle-app/eagle-app-base/src/test/resources/TestApplicationMetadata.xml
index df70e69..f04da60 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/resources/TestApplicationMetadata.xml
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/resources/TestApplicationMetadata.xml
@@ -20,7 +20,7 @@
     <type>TEST_APPLICATION</type>
     <name>Test Monitoring Application</name>
     <version>0.5.0-incubating</version>
-    <appClass>org.apache.eagle.app.TestStormAppImpl</appClass>
+    <appClass>org.apache.eagle.app.TestStormApplication</appClass>
     <viewPath>/apps/example</viewPath>
     <configuration>
         <property>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6f8b82ef/eagle-core/eagle-app/eagle-app-base/src/test/resources/providers.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/resources/providers.xml b/eagle-core/eagle-app/eagle-app-base/src/test/resources/providers.xml
index aba4c6c..4783773 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/resources/providers.xml
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/resources/providers.xml
@@ -18,6 +18,6 @@
 <providers>
     <provider>
         <jarPath>target/apache-eagle-example-app.jar</jarPath>
-        <className>org.apache.eagle.app.TestStormAppImpl$Provider</className>
+        <className>org.apache.eagle.app.TestStormApplication$Provider</className>
     </provider>
 </providers>
\ No newline at end of file


Mime
View raw message