falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samar...@apache.org
Subject [3/3] falcon git commit: FALCON-1030 Test for Add option to search for Entities. Contributed by Pragya M
Date Wed, 25 Feb 2015 05:40:22 GMT
FALCON-1030 Test for Add option to search for Entities. Contributed by Pragya M


Project: http://git-wip-us.apache.org/repos/asf/falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/falcon/commit/9dd0b27e
Tree: http://git-wip-us.apache.org/repos/asf/falcon/tree/9dd0b27e
Diff: http://git-wip-us.apache.org/repos/asf/falcon/diff/9dd0b27e

Branch: refs/heads/master
Commit: 9dd0b27e5543c1bc78e66c1f2a151edb887e7e77
Parents: 08c213f
Author: samarthg <samarthg@apacge.org>
Authored: Wed Feb 25 11:08:28 2015 +0530
Committer: samarthg <samarthg@apacge.org>
Committed: Wed Feb 25 11:08:28 2015 +0530

----------------------------------------------------------------------
 falcon-regression/CHANGES.txt                   |   2 +
 .../entity/EntitiesPatternSearchTest.java       | 196 +++++++++++++++++++
 2 files changed, 198 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/falcon/blob/9dd0b27e/falcon-regression/CHANGES.txt
----------------------------------------------------------------------
diff --git a/falcon-regression/CHANGES.txt b/falcon-regression/CHANGES.txt
index 234f52f..a115cf3 100644
--- a/falcon-regression/CHANGES.txt
+++ b/falcon-regression/CHANGES.txt
@@ -6,6 +6,8 @@ Trunk (Unreleased)
 
   NEW FEATURES
 
+   FALCON-1030 Test for Add option to search for Entities(Pragya Mittal Via Samarth Gupta)
+
    FALCON-1043 Add test in falcon to test touch feature(Pragya Mittal via Samarth Gupta)
  
 
    FALCON-1021 Add test in falcon to test feed SLA feature (Pragya Mittal via Raghav Kumar
Gautam)

http://git-wip-us.apache.org/repos/asf/falcon/blob/9dd0b27e/falcon-regression/merlin/src/test/java/org/apache/falcon/regression/entity/EntitiesPatternSearchTest.java
----------------------------------------------------------------------
diff --git a/falcon-regression/merlin/src/test/java/org/apache/falcon/regression/entity/EntitiesPatternSearchTest.java
b/falcon-regression/merlin/src/test/java/org/apache/falcon/regression/entity/EntitiesPatternSearchTest.java
new file mode 100644
index 0000000..f9fcf8d
--- /dev/null
+++ b/falcon-regression/merlin/src/test/java/org/apache/falcon/regression/entity/EntitiesPatternSearchTest.java
@@ -0,0 +1,196 @@
+/**
+ * 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.falcon.regression.entity;
+
+import org.apache.falcon.regression.Entities.ClusterMerlin;
+import org.apache.falcon.regression.Entities.FeedMerlin;
+import org.apache.falcon.regression.Entities.ProcessMerlin;
+import org.apache.falcon.regression.core.bundle.Bundle;
+import org.apache.falcon.regression.core.helpers.entity.AbstractEntityHelper;
+import org.apache.falcon.regression.core.util.*;
+import org.apache.falcon.regression.testHelper.BaseTestClass;
+import org.apache.falcon.resource.EntityList.EntityElement;
+import org.apache.hadoop.security.authentication.client.AuthenticationException;
+import org.apache.log4j.Logger;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.xml.bind.JAXBException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Testing the pattern serach of entities. Falcon-914
+ */
+@Test(groups = "embedded")
+public class EntitiesPatternSearchTest extends BaseTestClass {
+    private static final Logger LOGGER = Logger.getLogger(EntitiesPatternSearchTest.class);
+    private String baseTestHDFSDir = cleanAndGetTestDir();
+    private String aggregateWorkflowDir = baseTestHDFSDir + "/aggregator";
+
+    /**
+     * Upload feeds, processes and clusters with different names.
+     */
+    @BeforeClass(alwaysRun = true)
+    public void prepareData()
+        throws IOException, URISyntaxException, AuthenticationException, InterruptedException,
JAXBException {
+        uploadDirToClusters(aggregateWorkflowDir, OSUtil.RESOURCES_OOZIE);
+        removeTestClassEntities();
+
+        bundles[0] = BundleUtil.readELBundle();
+        bundles[0] = new Bundle(bundles[0], servers.get(0));
+        bundles[0].generateUniqueBundle(this);
+        bundles[0].setProcessWorkflow(aggregateWorkflowDir);
+        bundles[0].submitBundle(prism);
+
+        //submit different clusters, feeds and processes
+        FeedMerlin feed = new FeedMerlin(bundles[0].getInputFeedFromBundle());
+        ProcessMerlin process = new ProcessMerlin(bundles[0].getProcessData());
+        ClusterMerlin cluster = bundles[0].getClusterElement();
+        String clusterNamePrefix = bundles[0].getClusterElement().getName() + '-';
+        String processNamePrefix = bundles[0].getProcessName() + '-';
+        String feedNamePrefix = bundles[0].getInputFeedNameFromBundle() + '-';
+        List randomeNames = getPatternName();
+        for (int i = 0; i < randomeNames.size(); i++) {
+            process.setName(processNamePrefix + randomeNames.get(i));
+            AssertUtil.assertSucceeded(prism.getProcessHelper().submitAndSchedule(process.toString()));
+
+            feed.setName(feedNamePrefix + randomeNames.get(i));
+            AssertUtil.assertSucceeded(prism.getFeedHelper().submitAndSchedule(feed.toString()));
+
+            cluster.setName(clusterNamePrefix + randomeNames.get(i));
+            AssertUtil.assertSucceeded(prism.getClusterHelper().submitEntity(cluster.toString()));
+        }
+    }
+
+    @AfterClass(alwaysRun = true)
+    public void tearDown() throws IOException {
+        removeTestClassEntities();
+    }
+
+    /**
+     * Testing entity listing for patterns that match and validating the output for the same.
+     */
+    @Test(dataProvider = "getPattern")
+    public void listEntitiesWithPattern(AbstractEntityHelper helper, String patternParam)
+        throws AuthenticationException, IOException, URISyntaxException, InterruptedException
{
+        EntityElement[] entities =
+                helper.listAllEntities("pattern=" + patternParam, null).getEntityList().getElements();
+        LOGGER.info(helper.getEntityType() + " entities: " + Arrays.toString(entities));
+        validateOutputPatternList(helper.listEntities().getEntityList().getElements(), entities,
patternParam);
+    }
+
+    /**
+     * Testing entity listing for patterns that do not match and validating the output for
the same.
+     */
+    @Test(dataProvider = "getMismatchPattern")
+    public void listEntitiesWithPatternMismatch(AbstractEntityHelper helper, String mismatchPatternParam)
+        throws AuthenticationException, IOException, URISyntaxException, InterruptedException
{
+        mismatchPatternParam = mismatchPatternParam.replaceAll(" ", "%20");
+        EntityElement[] entities =
+                helper.listAllEntities("pattern=" + mismatchPatternParam, null).getEntityList().getElements();
+        LOGGER.info(helper.getEntityType() + " entities: " + Arrays.toString(entities));
+        Assert.assertNull(entities, "No pattern matches");
+    }
+
+    @DataProvider
+    public Object[][] getPattern() {
+        String[] patternParam =
+                new String[] {
+                    "new", "defintion", "W-E", "NewEntityDefinition", "ned",
+                    "NED", "NeD", "N-e-D", "N-e-D123", "", };
+        AbstractEntityHelper[] helper = new AbstractEntityHelper[] {
+                prism.getProcessHelper(),
+                prism.getFeedHelper(),
+                prism.getClusterHelper(),
+        };
+        return MatrixUtil.crossProduct(helper, patternParam);
+    }
+
+    @DataProvider
+    public Object[][] getMismatchPattern(){
+        String[] mismatchPatternParam = new String[]{"abc", "ne d", "newss", "new*", "NewEntityDefinitions"};
+        AbstractEntityHelper[] helper = new AbstractEntityHelper[] {
+                prism.getProcessHelper(),
+                prism.getFeedHelper(),
+                prism.getClusterHelper(),
+        };
+        return MatrixUtil.crossProduct(helper, mismatchPatternParam);
+    }
+
+    private void validateOutputPatternList(EntityElement[] entityElements,
+            EntityElement[] outputelements, String pattern) {
+        List<String> actualOutputElements = new ArrayList<String>();
+        List<String> expectedOutputElements = new ArrayList<String>();
+        for(EntityElement e : entityElements) {
+            if (getOutputEntity(e.name, pattern)) {
+                expectedOutputElements.add(e.name);
+            }
+        }
+
+        for(EntityElement e : outputelements) {
+            actualOutputElements.add(e.name);
+        }
+
+        LOGGER.debug("actualElement : " + actualOutputElements);
+        LOGGER.debug("expectedElement : " + expectedOutputElements);
+
+        // Checking no of elements present in output.
+        AssertUtil.checkForListSizes(expectedOutputElements, actualOutputElements);
+
+        //Checking expected out and actual output contains same enitities.
+        Assert.assertTrue(expectedOutputElements.containsAll(actualOutputElements),
+                "Output list elements are not as expected");
+
+        for(String element : expectedOutputElements) {
+            Assert.assertTrue(actualOutputElements.contains(element),
+                    "Element " + element + "is not present in output");
+        }
+    }
+
+    private Boolean getOutputEntity(String entityName, String pattern) {
+        String patternCheck="";
+        String regexString=".*";
+        StringBuffer newString = new StringBuffer();
+        char[] searchPattern = pattern.toLowerCase().toCharArray();
+        for(int i=0; i <searchPattern.length; i++) {
+            newString = newString.append(regexString).append(searchPattern[i]);
+        }
+        patternCheck = newString.append(regexString).toString();
+        LOGGER.info("patternCheck : " + patternCheck);
+        return entityName.toLowerCase().matches(patternCheck);
+    }
+
+    private List<String> getPatternName() {
+        List<String> nameList = new ArrayList<String>();
+        nameList.add("New-Entity-Definition");
+        nameList.add("NewEntityDefinition");
+        nameList.add("newentitydefine");
+        nameList.add("NEW-ENTITY");
+        nameList.add("NEW1-ENTITY2-DEFINITION123");
+        nameList.add("New-definition123");
+        return nameList;
+    }
+}


Mime
View raw message