http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/security/DefaultAuthorizationProviderTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/security/DefaultAuthorizationProviderTest.java b/common/src/test/java/org/apache/falcon/security/DefaultAuthorizationProviderTest.java deleted file mode 100644 index 3a6d8c0..0000000 --- a/common/src/test/java/org/apache/falcon/security/DefaultAuthorizationProviderTest.java +++ /dev/null @@ -1,403 +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 - * - * 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.security; - -import org.apache.falcon.FalconException; -import org.apache.falcon.cluster.util.EntityBuilderTestUtil; -import org.apache.falcon.entity.EntityNotRegisteredException; -import org.apache.falcon.entity.Storage; -import org.apache.falcon.entity.store.ConfigurationStore; -import org.apache.falcon.entity.v0.EntityType; -import org.apache.falcon.entity.v0.cluster.Cluster; -import org.apache.falcon.entity.v0.feed.CatalogTable; -import org.apache.falcon.entity.v0.feed.Feed; -import org.apache.falcon.entity.v0.feed.Location; -import org.apache.falcon.entity.v0.feed.LocationType; -import org.apache.falcon.entity.v0.feed.Locations; -import org.apache.falcon.util.FalconTestUtil; -import org.apache.falcon.util.StartupProperties; -import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.security.authorize.AuthorizationException; -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 java.util.Collection; - -/** - * Unit tests for DefaultAuthorizationProvider. - */ -public class DefaultAuthorizationProviderTest { - - public static final String CLUSTER_ENTITY_NAME = "primary-cluster"; - public static final String PROCESS_ENTITY_NAME = "sample-process"; - - private UserGroupInformation realUser; - private ConfigurationStore configStore; - private Cluster clusterEntity; - private Feed feedEntity; - private org.apache.falcon.entity.v0.process.Process processEntity; - - @BeforeClass - public void setUp() throws Exception { - realUser = UserGroupInformation.createUserForTesting(FalconTestUtil.TEST_USER_1, new String[]{"falcon", }); - - CurrentUser.authenticate(EntityBuilderTestUtil.USER); - org.testng.Assert.assertEquals(CurrentUser.getUser(), EntityBuilderTestUtil.USER); - - configStore = ConfigurationStore.get(); - - addClusterEntity(); - addFeedEntity(); - addProcessEntity(); - org.testng.Assert.assertNotNull(processEntity); - } - - public void addClusterEntity() throws Exception { - clusterEntity = EntityBuilderTestUtil.buildCluster(CLUSTER_ENTITY_NAME); - configStore.publish(EntityType.CLUSTER, clusterEntity); - } - - public void addFeedEntity() throws Exception { - feedEntity = EntityBuilderTestUtil.buildFeed("sample-feed", clusterEntity, - "classified-as=Secure", "analytics"); - addStorage(feedEntity, Storage.TYPE.FILESYSTEM, "/falcon/impression-feed/${YEAR}/${MONTH}/${DAY}"); - configStore.publish(EntityType.FEED, feedEntity); - } - - private static void addStorage(Feed feed, Storage.TYPE storageType, String uriTemplate) { - if (storageType == Storage.TYPE.FILESYSTEM) { - Locations locations = new Locations(); - feed.setLocations(locations); - - Location location = new Location(); - location.setType(LocationType.DATA); - location.setPath(uriTemplate); - feed.getLocations().getLocations().add(location); - } else { - CatalogTable table = new CatalogTable(); - table.setUri(uriTemplate); - feed.setTable(table); - } - } - - public void addProcessEntity() throws Exception { - processEntity = EntityBuilderTestUtil.buildProcess(PROCESS_ENTITY_NAME, - clusterEntity, "classified-as=Critical"); - EntityBuilderTestUtil.addProcessWorkflow(processEntity); - EntityBuilderTestUtil.addProcessACL(processEntity); - - configStore.publish(EntityType.PROCESS, processEntity); - } - - @AfterClass - public void tearDown() throws Exception { - cleanupStore(); - } - - protected void cleanupStore() throws FalconException { - configStore = ConfigurationStore.get(); - for (EntityType type : EntityType.values()) { - Collection<String> entities = configStore.getEntities(type); - for (String entity : entities) { - configStore.remove(type, entity); - } - } - } - - @Test - public void testAuthorizeAdminResourceVersionAction() throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "blah", realUser, new String[]{"blah-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("admin", "version", null, null, proxyUgi); - } - - @Test - public void testAuthorizeSuperUser() throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - EntityBuilderTestUtil.USER, realUser, new String[]{"group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", "schedule", "feed", feedEntity.getName(), proxyUgi); - provider.authorizeResource("instance", "status", "feed", feedEntity.getName(), proxyUgi); - } - - @Test - public void testAuthorizeSuperUserGroup() throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "blah", realUser, new String[]{"falcon", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", "schedule", "feed", feedEntity.getName(), proxyUgi); - provider.authorizeResource("instance", "status", "feed", feedEntity.getName(), proxyUgi); - } - - @DataProvider(name = "adminResourceActions") - private Object[][] createAdminResourceActions() { - return new Object[][] { - {"version"}, - {"stack"}, - {"config"}, - }; - } - - @Test (dataProvider = "adminResourceActions") - public void testAuthorizeAdminResourceAdmin(String action) throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("admin", action, null, null, proxyUgi); - } - - @Test - public void testAuthorizeAdminResourceAdminUserBadGroup() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("admin", "version", null, null, proxyUgi); - } - - @Test - public void testAuthorizeAdminResourceAdminGroupBadUser() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty( - "falcon.security.authorization.admin.groups", "admin-group"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin-user", realUser, new String[]{"admin-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("admin", "version", null, null, proxyUgi); - } - - @Test (expectedExceptions = AuthorizationException.class) - public void testAuthorizeAdminResourceInvalidUserAndGroup() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin-user", realUser, new String[]{"admin-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("admin", "stack", null, null, proxyUgi); - Assert.fail("User does not belong to both admin-users not groups"); - } - - @DataProvider(name = "entityResourceActions") - private Object[][] createEntityResourceActions() { - return new Object[][] { - {"entities", "list", "feed"}, - {"entities", "list", "process"}, - {"entities", "list", "cluster"}, - }; - } - - @Test (dataProvider = "entityResourceActions") - public void testAuthorizeEntitiesInstancesReadOnlyResource(String resource, - String action, - String entityType) throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin-user", realUser, new String[]{"admin-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource(resource, action, entityType, null, proxyUgi); - } - - @DataProvider(name = "entityLifecycleResourceActions") - private Object[][] createEntityLifecycleResourceActions() { - return new Object[][] { - {"entities", "status", "cluster", "primary-cluster"}, - {"entities", "status", "process", "sample-process"}, - {"entities", "status", "feed", "sample-feed"}, - {"instance", "status", "process", "sample-process"}, - {"instance", "running", "process", "sample-process"}, - {"instance", "running", "feed", "sample-feed"}, - }; - } - - @Test(dataProvider = "entityLifecycleResourceActions") - public void testAuthorizeEntitiesInstancesLifecycleResource(String resource, String action, - String entityType, - String entityName) throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - EntityBuilderTestUtil.USER, realUser, new String[]{EntityBuilderTestUtil.USER, }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource(resource, action, entityType, entityName, proxyUgi); - } - - @Test(dataProvider = "entityLifecycleResourceActions", - expectedExceptions = AuthorizationException.class) - public void testAuthorizeEntitiesInstancesLifecycleResourceBadUGI(String resource, - String action, - String entityType, - String entityName) - throws Exception { - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin-user", realUser, new String[]{"admin-group", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource(resource, action, entityType, entityName, proxyUgi); - } - - @Test (expectedExceptions = IllegalArgumentException.class) - public void testAuthorizeBadResource() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("invalid", "version", null, null, proxyUgi); - Assert.fail("Bad resource"); - } - - @Test (expectedExceptions = IllegalArgumentException.class) - public void testAuthorizeNullResource() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource(null, "version", null, null, proxyUgi); - Assert.fail("Bad resource"); - } - - @Test (expectedExceptions = IllegalArgumentException.class) - public void testAuthorizeBadAction() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", null, "feedz", null, proxyUgi); - Assert.fail("Bad action"); - } - - @Test (expectedExceptions = IllegalArgumentException.class) - public void testAuthorizeNullEntityType() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", "list", null, "primary-cluster", proxyUgi); - Assert.fail("Bad entity type"); - } - - @Test (expectedExceptions = IllegalArgumentException.class) - public void testAuthorizeBadEntityType() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", "list", "clusterz", "primary-cluster", proxyUgi); - Assert.fail("Bad entity type"); - } - - @Test - public void testAuthorizeValidatePOSTOperations() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - EntityBuilderTestUtil.addProcessACL(processEntity, "admin", "admin"); - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeEntity(processEntity.getName(), "process", - processEntity.getACL(), "submit", proxyUgi); - } - - @Test (expectedExceptions = EntityNotRegisteredException.class) - public void testAuthorizeResourceOperationsBadEntity() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("entities", "status", "process", feedEntity.getName(), proxyUgi); - Assert.fail("Bad entity"); - } - - @Test - public void testAuthorizeValidatePOSTOperationsGroupBadUser() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - EntityBuilderTestUtil.addProcessACL(processEntity, "admin-user", "admin"); - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeEntity(processEntity.getName(), "process", - processEntity.getACL(), "submit", proxyUgi); - } - - @Test (expectedExceptions = AuthorizationException.class) - public void testAuthorizeValidatePOSTOperationsBadUserAndGroup() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - EntityBuilderTestUtil.addProcessACL(processEntity, "admin-user", "admin-group"); - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeEntity(processEntity.getName(), "process", - processEntity.getACL(), "submit", proxyUgi); - } - - @Test - public void testAuthorizeLineageResource() throws Exception { - StartupProperties.get().setProperty("falcon.security.authorization.admin.users", "admin"); - StartupProperties.get().setProperty("falcon.security.authorization.admin.groups", "admin"); - - UserGroupInformation proxyUgi = UserGroupInformation.createProxyUserForTesting( - "admin", realUser, new String[]{"admin", }); - - DefaultAuthorizationProvider provider = new DefaultAuthorizationProvider(); - provider.authorizeResource("metadata", "lineage", null, null, proxyUgi); - } -}
http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/security/SecurityUtilTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/security/SecurityUtilTest.java b/common/src/test/java/org/apache/falcon/security/SecurityUtilTest.java deleted file mode 100644 index d47acbc..0000000 --- a/common/src/test/java/org/apache/falcon/security/SecurityUtilTest.java +++ /dev/null @@ -1,162 +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 - * - * 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.security; - - -import org.apache.falcon.FalconException; -import org.apache.falcon.entity.v0.process.ACL; -import org.apache.falcon.entity.v0.process.Process; -import org.apache.falcon.service.GroupsService; -import org.apache.falcon.service.ProxyUserService; -import org.apache.falcon.service.Services; -import org.apache.falcon.util.FalconTestUtil; -import org.apache.falcon.util.StartupProperties; -import org.apache.falcon.util.RuntimeProperties; -import org.mockito.Mockito; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.IOException; - -/** - * Unit test for Security utils. - */ -public class SecurityUtilTest { - - private ProxyUserService proxyUserService; - private GroupsService groupsService; - - @BeforeClass - public void setUp() throws Exception { - Services.get().register(new ProxyUserService()); - Services.get().register(new GroupsService()); - groupsService = Services.get().getService(GroupsService.SERVICE_NAME); - proxyUserService = Services.get().getService(ProxyUserService.SERVICE_NAME); - groupsService.init(); - - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - } - - @AfterClass - public void tearDown() throws Exception { - proxyUserService.destroy(); - groupsService.destroy(); - Services.get().reset(); - } - - @Test - public void testDefaultGetAuthenticationType() throws Exception { - Assert.assertEquals(SecurityUtil.getAuthenticationType(), "simple"); - } - - @Test - public void testGetAuthenticationType() throws Exception { - try { - StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, "kerberos"); - Assert.assertEquals(SecurityUtil.getAuthenticationType(), "kerberos"); - } finally { - // reset - StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, "simple"); - } - } - - @Test - public void testIsSecurityEnabledByDefault() throws Exception { - Assert.assertFalse(SecurityUtil.isSecurityEnabled()); - } - - @Test - public void testIsSecurityEnabled() throws Exception { - try { - StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, "kerberos"); - Assert.assertTrue(SecurityUtil.isSecurityEnabled()); - } finally { - // reset - StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, "simple"); - } - } - - @Test - public void testIsAuthorizationEnabledByDefault() throws Exception { - Assert.assertFalse(SecurityUtil.isAuthorizationEnabled()); - } - - @Test - public void testIsAuthorizationEnabled() throws Exception { - try { - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); - Assert.assertTrue(SecurityUtil.isAuthorizationEnabled()); - } finally { - // reset - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "false"); - } - } - - @Test - public void testGetAuthorizationProviderByDefault() throws Exception { - Assert.assertNotNull(SecurityUtil.getAuthorizationProvider()); - Assert.assertEquals(SecurityUtil.getAuthorizationProvider().getClass(), - DefaultAuthorizationProvider.class); - } - - @Test - public void testTryProxy() throws IOException, FalconException { - Process process = Mockito.mock(Process.class); - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); - final String currentUser = System.getProperty("user.name"); - - // When ACL not specified - CurrentUser.authenticate(currentUser); - SecurityUtil.tryProxy(process, ""); - Assert.assertEquals(CurrentUser.getUser(), currentUser); - - ACL acl = new ACL(); - acl.setOwner(FalconTestUtil.TEST_USER_2); - acl.setGroup("users"); - Mockito.when(process.getACL()).thenReturn(acl); - - // When ACL is specified - SecurityUtil.tryProxy(process, ""); - Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2); - } - - @Test (expectedExceptions = FalconException.class, - expectedExceptionsMessageRegExp = "doAs user and ACL owner mismatch.*") - public void testTryProxyWithDoAsUser() throws IOException, FalconException { - Process process = Mockito.mock(Process.class); - StartupProperties.get().setProperty("falcon.security.authorization.enabled", "true"); - final String currentUser = "foo"; - - ACL acl = new ACL(); - acl.setOwner(FalconTestUtil.TEST_USER_2); - acl.setGroup("users"); - Mockito.when(process.getACL()).thenReturn(acl); - - CurrentUser.authenticate(currentUser); - CurrentUser.proxyDoAsUser("doAsUser", "localhost"); - - Assert.assertEquals(CurrentUser.getUser(), "doAsUser"); - SecurityUtil.tryProxy(process, "doAsUser"); - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/service/GroupsServiceTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/service/GroupsServiceTest.java b/common/src/test/java/org/apache/falcon/service/GroupsServiceTest.java deleted file mode 100644 index be5cbe7..0000000 --- a/common/src/test/java/org/apache/falcon/service/GroupsServiceTest.java +++ /dev/null @@ -1,56 +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 - * - * 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.service; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.testng.Assert; - -import java.util.List; - -/** - * Unit tests for GroupsService. - */ -public class GroupsServiceTest { - - private GroupsService service; - - @BeforeClass - public void setUp() throws Exception { - service = new GroupsService(); - service.init(); - } - - @AfterClass - public void tearDown() throws Exception { - service.destroy(); - } - - @Test - public void testGetName() throws Exception { - Assert.assertEquals(service.getName(), GroupsService.SERVICE_NAME); - } - - @Test - public void testGroupsService() throws Exception { - List<String> g = service.getGroups(System.getProperty("user.name")); - Assert.assertNotSame(g.size(), 0); - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/service/ProxyUserServiceTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/service/ProxyUserServiceTest.java b/common/src/test/java/org/apache/falcon/service/ProxyUserServiceTest.java deleted file mode 100644 index 83ec6c2..0000000 --- a/common/src/test/java/org/apache/falcon/service/ProxyUserServiceTest.java +++ /dev/null @@ -1,167 +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 - * - * 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.service; - -import org.apache.falcon.FalconException; -import org.apache.falcon.util.RuntimeProperties; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.security.AccessControlException; -import java.util.List; - -/** - * Unit tests for ProxyUserService. - */ -public class ProxyUserServiceTest { - - private ProxyUserService proxyUserService; - private GroupsService groupsService; - - @BeforeClass - public void setUp() throws Exception { - Services.get().register(new ProxyUserService()); - Services.get().register(new GroupsService()); - - groupsService = Services.get().getService(GroupsService.SERVICE_NAME); - proxyUserService = Services.get().getService(ProxyUserService.SERVICE_NAME); - groupsService.init(); - } - - @AfterClass - public void tearDown() throws Exception { - proxyUserService.destroy(); - groupsService.destroy(); - Services.get().reset(); - } - - @Test - public void testGetName() throws Exception { - proxyUserService.init(); - Assert.assertEquals(proxyUserService.getName(), ProxyUserService.SERVICE_NAME); - } - - @Test (expectedExceptions = FalconException.class, expectedExceptionsMessageRegExp = ".*falcon.service" - + ".ProxyUserService.proxyuser.foo.groups property not set in runtime properties.*") - public void testWrongConfigGroups() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().remove("falcon.service.ProxyUserService.proxyuser.foo.groups"); - proxyUserService.init(); - } - - @Test (expectedExceptions = FalconException.class, expectedExceptionsMessageRegExp = ".*falcon.service" - + ".ProxyUserService.proxyuser.foo.hosts property not set in runtime properties.*") - public void testWrongConfigHosts() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - RuntimeProperties.get().remove("falcon.service.ProxyUserService.proxyuser.foo.hosts"); - proxyUserService.init(); - } - - @Test (expectedExceptions = FalconException.class, - expectedExceptionsMessageRegExp = "Exception normalizing host name.*") - public void testWrongHost() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "otherhost"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - } - - @Test - public void testValidateAnyHostAnyUser() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - proxyUserService.validate("foo", "localhost", "bar"); - } - - @Test (expectedExceptions = AccessControlException.class, - expectedExceptionsMessageRegExp = "User .* not defined as proxyuser.*") - public void testInvalidProxyUser() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - proxyUserService.validate("bar", "localhost", "foo"); - } - - @Test - public void testValidateHost() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - proxyUserService.validate("foo", "localhost", "bar"); - } - - private String getGroup() throws Exception { - List<String> g = groupsService.getGroups(System.getProperty("user.name")); - return g.get(0); - } - - @Test - public void testValidateGroup() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "*"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", - getGroup()); - - proxyUserService.init(); - proxyUserService.validate("foo", "localhost", System.getProperty("user.name")); - } - - @Test (expectedExceptions = AccessControlException.class, - expectedExceptionsMessageRegExp = "Could not resolve host .*") - public void testUnknownHost() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "localhost"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - proxyUserService.validate("foo", "unknownhost.bar.foo", "bar"); - } - - @Test (expectedExceptions = AccessControlException.class, - expectedExceptionsMessageRegExp = "Unauthorized host .*") - public void testInvalidHost() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "localhost"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "*"); - proxyUserService.init(); - proxyUserService.validate("foo", "www.example.com", "bar"); - } - - @Test (expectedExceptions = AccessControlException.class, - expectedExceptionsMessageRegExp = "Unauthorized proxyuser .*, not in proxyuser groups") - public void testInvalidGroup() throws Exception { - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.hosts", "localhost"); - RuntimeProperties.get().setProperty("falcon.service.ProxyUserService.proxyuser.foo.groups", "nobody"); - proxyUserService.init(); - proxyUserService.validate("foo", "localhost", System.getProperty("user.name")); - } - - @Test (expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = "proxyUser cannot be null or empty, .*") - public void testNullProxyUser() throws Exception { - proxyUserService.init(); - proxyUserService.validate(null, "localhost", "bar"); - } - - @Test (expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = "proxyHost cannot be null or empty, .*") - public void testNullHost() throws Exception { - proxyUserService.init(); - proxyUserService.validate("foo", null, "bar"); - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/update/UpdateHelperTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/update/UpdateHelperTest.java b/common/src/test/java/org/apache/falcon/update/UpdateHelperTest.java deleted file mode 100644 index 3e48e26..0000000 --- a/common/src/test/java/org/apache/falcon/update/UpdateHelperTest.java +++ /dev/null @@ -1,323 +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 - * - * 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.update; - -import org.apache.falcon.FalconException; -import org.apache.falcon.cluster.util.EmbeddedCluster; -import org.apache.falcon.entity.AbstractTestBase; -import org.apache.falcon.entity.EntityUtil; -import org.apache.falcon.entity.FeedHelper; -import org.apache.falcon.entity.parser.EntityParserFactory; -import org.apache.falcon.entity.parser.FeedEntityParser; -import org.apache.falcon.entity.parser.ProcessEntityParser; -import org.apache.falcon.entity.store.ConfigurationStore; -import org.apache.falcon.entity.v0.EntityType; -import org.apache.falcon.entity.v0.Frequency; -import org.apache.falcon.entity.v0.SchemaHelper; -import org.apache.falcon.entity.v0.cluster.Cluster; -import org.apache.falcon.entity.v0.feed.CatalogTable; -import org.apache.falcon.entity.v0.feed.Feed; -import org.apache.falcon.entity.v0.feed.Location; -import org.apache.falcon.entity.v0.feed.LocationType; -import org.apache.falcon.entity.v0.feed.Locations; -import org.apache.falcon.entity.v0.feed.Partition; -import org.apache.falcon.entity.v0.feed.Properties; -import org.apache.falcon.entity.v0.feed.Property; -import org.apache.falcon.entity.v0.process.LateProcess; -import org.apache.falcon.entity.v0.process.PolicyType; -import org.apache.falcon.entity.v0.process.Process; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Test for Update helper methods. - */ -public class UpdateHelperTest extends AbstractTestBase { - private final FeedEntityParser parser = (FeedEntityParser)EntityParserFactory.getParser(EntityType.FEED); - private final ProcessEntityParser processParser = - (ProcessEntityParser)EntityParserFactory.getParser(EntityType.PROCESS); - - @BeforeClass - public void init() throws Exception { - this.dfsCluster = EmbeddedCluster.newCluster("testCluster"); - this.conf = dfsCluster.getConf(); - setup(); - } - - @AfterClass - public void tearDown() { - this.dfsCluster.shutdown(); - } - - @BeforeMethod - public void setUp() throws Exception { - storeEntity(EntityType.CLUSTER, "testCluster"); - storeEntity(EntityType.CLUSTER, "backupCluster"); - storeEntity(EntityType.FEED, "clicksFeed"); - storeEntity(EntityType.FEED, "impressionFeed"); - storeEntity(EntityType.FEED, "imp-click-join1"); - storeEntity(EntityType.FEED, "imp-click-join2"); - } - - private void prepare(Process process) throws IOException, FalconException { - FileSystem fs = dfsCluster.getFileSystem(); - Cluster clusterEntity = ConfigurationStore.get().get(EntityType.CLUSTER, "testCluster"); - Path staging = EntityUtil.getNewStagingPath(clusterEntity, process); - fs.mkdirs(staging); - fs.create(new Path(staging, "workflow.xml")).close(); - fs.create(new Path(staging, "checksums")).close(); - } - - @Test - public void testIsEntityUpdated() throws Exception { - Feed oldFeed = parser.parseAndValidate(this.getClass().getResourceAsStream(FEED_XML)); - String cluster = "testCluster"; - Feed newFeed = (Feed) oldFeed.copy(); - Cluster clusterEntity = ConfigurationStore.get().get(EntityType.CLUSTER, cluster); - - Path feedPath = EntityUtil.getNewStagingPath(clusterEntity, oldFeed); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - - //Add tags and ensure isEntityUpdated returns false - newFeed.setTags("category=test"); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - - newFeed.setGroups("newgroups"); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - newFeed.getLateArrival().setCutOff(Frequency.fromString("hours(8)")); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - newFeed.setFrequency(Frequency.fromString("days(1)")); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - - Process oldProcess = processParser.parseAndValidate(this.getClass().getResourceAsStream(PROCESS_XML)); - prepare(oldProcess); - Process newProcess = (Process) oldProcess.copy(); - Path procPath = EntityUtil.getNewStagingPath(clusterEntity, oldProcess); - - newProcess.getRetry().setPolicy(PolicyType.FINAL); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - newProcess.getLateProcess().getLateInputs().remove(1); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - newProcess.getLateProcess().setPolicy(PolicyType.PERIODIC); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - newProcess.setFrequency(Frequency.fromString("days(1)")); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - - //Adding new cluster shouldn't cause update in the old cluster - newProcess = (Process) oldProcess.copy(); - org.apache.falcon.entity.v0.process.Cluster procCluster = new org.apache.falcon.entity.v0.process.Cluster(); - procCluster.setName("newcluster"); - procCluster.setValidity(newProcess.getClusters().getClusters().get(0).getValidity()); - newProcess.getClusters().getClusters().add(procCluster); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - - //change pipelines and ensure it doesn't cause an update - oldProcess.setPipelines("test"); - newProcess.setPipelines("newTest"); - newProcess.setTags("category=test"); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - - //In the case of incomplete update, where new entity is scheduled but still not updated in config store, - //another update call shouldn't cause update in workflow engine - newProcess.setFrequency(Frequency.fromString("days(1)")); - procPath = EntityUtil.getNewStagingPath(clusterEntity, newProcess); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - } - - @Test - public void testShouldUpdateAffectedEntities() throws Exception { - Feed oldFeed = parser.parseAndValidate(this.getClass().getResourceAsStream(FEED_XML)); - - Feed newFeed = (Feed) oldFeed.copy(); - Process process = processParser.parseAndValidate(this.getClass().getResourceAsStream(PROCESS_XML)); - prepare(process); - String cluster = process.getClusters().getClusters().get(0).getName(); - - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - newFeed.getLateArrival().setCutOff(Frequency.fromString("hours(1)")); - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - newFeed.getLateArrival().setCutOff(oldFeed.getLateArrival().getCutOff()); - getLocation(newFeed, LocationType.DATA, cluster).setPath("/test"); - Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - getLocation(newFeed, LocationType.DATA, cluster).setPath( - getLocation(oldFeed, LocationType.DATA, cluster).getPath()); - newFeed.setFrequency(Frequency.fromString("months(1)")); - Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - newFeed.setFrequency(oldFeed.getFrequency()); - Partition partition = new Partition(); - partition.setName("1"); - newFeed.getPartitions().getPartitions().add(partition); - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - Property property = new Property(); - property.setName("1"); - property.setValue("1"); - newFeed.setProperties(new Properties()); - newFeed.getProperties().getProperties().add(property); - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - newFeed.getProperties().getProperties().remove(0); - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - //Change in start time should trigger process update as instance time changes - FeedHelper.getCluster(newFeed, process.getClusters().getClusters().get(0).getName()).getValidity().setStart( - SchemaHelper.parseDateUTC("2012-11-01T00:00Z")); - Assert.assertTrue(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - - FeedHelper.getCluster(newFeed, process.getClusters().getClusters().get(0).getName()).getValidity(). - setStart(FeedHelper.getCluster(oldFeed, - process.getClusters().getClusters().get(0).getName()).getValidity().getStart()); - - //Change location to table should trigger process update - newFeed.setLocations(null); - CatalogTable table = new CatalogTable(); - table.setUri("catalog:default:clicks-blah#ds=${YEAR}-${MONTH}-${DAY}-${HOUR}"); - newFeed.setTable(table); - Assert.assertFalse(UpdateHelper.shouldUpdate(oldFeed, newFeed, process, cluster)); - } - - @Test - public void testIsEntityUpdatedTable() throws Exception { - InputStream inputStream = getClass().getResourceAsStream("/config/feed/hive-table-feed.xml"); - Feed oldTableFeed = (Feed) EntityType.FEED.getUnmarshaller().unmarshal(inputStream); - getStore().publish(EntityType.FEED, oldTableFeed); - - String cluster = "testCluster"; - Cluster clusterEntity = ConfigurationStore.get().get(EntityType.CLUSTER, cluster); - Path feedPath = EntityUtil.getNewStagingPath(clusterEntity, oldTableFeed); - Feed newTableFeed = (Feed) oldTableFeed.copy(); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldTableFeed, newTableFeed, cluster, feedPath)); - - newTableFeed.setGroups("newgroups"); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldTableFeed, newTableFeed, cluster, feedPath)); - newTableFeed.setFrequency(Frequency.fromString("days(1)")); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldTableFeed, newTableFeed, cluster, feedPath)); - - final CatalogTable table = new CatalogTable(); - table.setUri("catalog:default:clicks-blah#ds=${YEAR}-${MONTH}-${DAY}-${HOUR}"); - newTableFeed.setTable(table); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldTableFeed, newTableFeed, cluster, feedPath)); - - inputStream = getClass().getResourceAsStream("/config/process/process-table.xml"); - Process oldProcess = (Process) EntityType.PROCESS.getUnmarshaller().unmarshal(inputStream); - FileSystem fs = dfsCluster.getFileSystem(); - Path staging = EntityUtil.getNewStagingPath(clusterEntity, oldProcess); - fs.mkdirs(staging); - fs.create(new Path(staging, "workflow.xml")).close(); - fs.create(new Path(staging, "checksums")).close(); - Process newProcess = (Process) oldProcess.copy(); - Path procPath = EntityUtil.getNewStagingPath(clusterEntity, oldProcess); - - newProcess.getRetry().setPolicy(PolicyType.FINAL); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - newProcess.setFrequency(Frequency.fromString("days(1)")); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - } - - @Test - public void testIsEntityACLUpdated() throws Exception { - Feed oldFeed = parser.parseAndValidate(this.getClass().getResourceAsStream(FEED_XML)); - String cluster = "testCluster"; - Feed newFeed = (Feed) oldFeed.copy(); - Cluster clusterEntity = ConfigurationStore.get().get(EntityType.CLUSTER, cluster); - - Path feedPath = EntityUtil.getNewStagingPath(clusterEntity, oldFeed); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - - newFeed.getACL().setOwner("new-user"); - newFeed.getACL().setGroup("new-group"); - Assert.assertNotEquals(oldFeed.getACL().getOwner(), newFeed.getACL().getOwner()); - Assert.assertNotEquals(oldFeed.getACL().getGroup(), newFeed.getACL().getGroup()); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldFeed, newFeed, cluster, feedPath)); - - Process oldProcess = processParser.parseAndValidate(this.getClass().getResourceAsStream(PROCESS_XML)); - prepare(oldProcess); - Process newProcess = (Process) oldProcess.copy(); - Path procPath = EntityUtil.getNewStagingPath(clusterEntity, oldProcess); - - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - org.apache.falcon.entity.v0.process.ACL processACL = - new org.apache.falcon.entity.v0.process.ACL(); - processACL.setOwner("owner"); - processACL.setOwner("group"); - newProcess.setACL(processACL); - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - } - - @Test - public void testIsEntityLateProcessUpdated() throws Exception { - String cluster = "testCluster"; - Cluster clusterEntity = ConfigurationStore.get().get(EntityType.CLUSTER, cluster); - Process oldProcess = processParser.parseAndValidate(this.getClass().getResourceAsStream(PROCESS_XML)); - prepare(oldProcess); - Path procPath = EntityUtil.getNewStagingPath(clusterEntity, oldProcess); - - // The Process should not be updated when late processing is updated. - // As the definition does not affect the Oozie workflow. - Process newProcess = (Process) oldProcess.copy(); - newProcess.getLateProcess().setPolicy(PolicyType.FINAL); - Assert.assertFalse(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - - LateProcess lateProcess = newProcess.getLateProcess(); - newProcess.setLateProcess(null); - - // The Process should be updated when late processing is removed. - // Pre-processing needs to be removed from the workflow - Assert.assertTrue(UpdateHelper.isEntityUpdated(oldProcess, newProcess, cluster, procPath)); - - Process newerProcess = (Process) newProcess.copy(); - newerProcess.setLateProcess(lateProcess); - - // The Process should be updated when late processing is added. - // Pre-processing needs to be added to the workflow - Assert.assertTrue(UpdateHelper.isEntityUpdated(newProcess, newerProcess, cluster, procPath)); - } - - private static Location getLocation(Feed feed, LocationType type, String cluster) { - org.apache.falcon.entity.v0.feed.Cluster feedCluster = FeedHelper.getCluster(feed, cluster); - if (feedCluster.getLocations() != null) { - return getLocation(feedCluster.getLocations(), type); - } - return getLocation(feed.getLocations(), type); - } - - private static Location getLocation(Locations locations, LocationType type) { - for (Location loc : locations.getLocations()) { - if (loc.getType() == type) { - return loc; - } - } - Location loc = new Location(); - loc.setPath("/tmp"); - loc.setType(type); - return loc; - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/ApplicationPropertiesTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/ApplicationPropertiesTest.java b/common/src/test/java/org/apache/falcon/util/ApplicationPropertiesTest.java deleted file mode 100644 index d899d53..0000000 --- a/common/src/test/java/org/apache/falcon/util/ApplicationPropertiesTest.java +++ /dev/null @@ -1,111 +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 - * - * 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.util; - -import org.apache.falcon.FalconException; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.FileOutputStream; - -/** - * Test for Application properties test. - */ -public class ApplicationPropertiesTest { - - @Test - public void testConfigLocation() throws Exception { - File target = new File("target"); - if (!target.exists()) { - target = new File("common/target"); - } - - FileOutputStream out = new FileOutputStream(new File(target, "config.properties")); - out.write("*.domain=unittest\n".getBytes()); - out.write("unittest.test=hello world\n".getBytes()); - out.close(); - ApplicationProperties configLocation = new ConfigLocation(); - configLocation.loadProperties("config.properties", target.getAbsolutePath()); - Assert.assertEquals(configLocation.getDomain(), "unittest"); - Assert.assertEquals(configLocation.get("test"), "hello world"); - } - - @Test - public void testClassPathLocation() throws Exception { - ApplicationProperties classPathLocation = new ClassPathLocation(); - classPathLocation.loadProperties("classpath.properties", null); - Assert.assertEquals(classPathLocation.getDomain(), "unittest"); - Assert.assertEquals(classPathLocation.get("test"), "hello world"); - } - - @Test - public void testPropertiesWithSpaces() throws Exception{ - ApplicationProperties properties = new ConfigLocation(); - properties.put("key1", "value with trailing spaces. "); - properties.put("key2", " value with leading spaces."); - properties.put("key3", " value with spaces on both ends. "); - Assert.assertEquals(properties.getProperty("key1"), "value with trailing spaces."); - Assert.assertEquals(properties.getProperty("key2"), "value with leading spaces."); - Assert.assertEquals(properties.getProperty("key3"), "value with spaces on both ends."); - } - - @Test (expectedExceptions = FalconException.class) - public void testMissingLocation() throws FalconException { - new MissingLocation().loadProperties(); - } - - private class ConfigLocation extends ApplicationProperties { - - protected ConfigLocation() throws FalconException { - } - - protected void init() {} - - @Override - protected String getPropertyFile() { - return "config.properties"; - } - } - - private class ClassPathLocation extends ApplicationProperties { - - protected ClassPathLocation() throws FalconException { - } - - protected void init() {} - - @Override - protected String getPropertyFile() { - return "classpath.properties"; - } - } - - private class MissingLocation extends ApplicationProperties { - - protected MissingLocation() throws FalconException { - } - - @Override - protected String getPropertyFile() { - return "missing.properties"; - } - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/FalconTestUtil.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/FalconTestUtil.java b/common/src/test/java/org/apache/falcon/util/FalconTestUtil.java deleted file mode 100644 index 2a890ae..0000000 --- a/common/src/test/java/org/apache/falcon/util/FalconTestUtil.java +++ /dev/null @@ -1,33 +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 - * - * 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.util; - -/** - * Utilities for falcon unit tests. - */ -public final class FalconTestUtil { - - public static final String TEST_USER_1 = "falcon-ut-user"; - public static final String TEST_USER_2 = "testuser-ut-user"; - - private FalconTestUtil() { - //default constructor to avoid - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/HadoopQueueUtilTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/HadoopQueueUtilTest.java b/common/src/test/java/org/apache/falcon/util/HadoopQueueUtilTest.java deleted file mode 100644 index bb37343..0000000 --- a/common/src/test/java/org/apache/falcon/util/HadoopQueueUtilTest.java +++ /dev/null @@ -1,63 +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 - * - * 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.util; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.HashSet; -import java.util.Set; - -/** - * Utilities for falcon unit tests. - */ -public final class HadoopQueueUtilTest { - - @Test - public void testGetHadoopClusterQueueNamesHelper1() throws Exception { - final InputStream inputStream = this.getClass().getResourceAsStream("/config/feed/feed-schedulerinfo-1.json"); - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); - String jsonResult = ""; - String line; - while((line = br.readLine()) != null) { - jsonResult += line; - } - Set<String> qNames = new HashSet<>(); - HadoopQueueUtil.getHadoopClusterQueueNamesHelper(jsonResult, qNames); - Assert.assertEquals(qNames.size(), 9); - } - - @Test - public void testGetHadoopClusterQueueNamesHelper2() throws Exception { - final InputStream inputStream = this.getClass().getResourceAsStream("/config/feed/feed-schedulerinfo-2.json"); - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); - String jsonResult = ""; - String line; - while((line = br.readLine()) != null) { - jsonResult += line; - } - Set<String> qNames = new HashSet<>(); - HadoopQueueUtil.getHadoopClusterQueueNamesHelper(jsonResult, qNames); - Assert.assertTrue(qNames.contains("default")); - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/RadixNodeTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/RadixNodeTest.java b/common/src/test/java/org/apache/falcon/util/RadixNodeTest.java deleted file mode 100644 index aea28e6..0000000 --- a/common/src/test/java/org/apache/falcon/util/RadixNodeTest.java +++ /dev/null @@ -1,109 +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 - * - * 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.util; - -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Arrays; -import java.util.HashSet; - -/** - * Tests for Radix Node. - */ -public class RadixNodeTest { - private RadixNode<String> rootNode = new RadixNode<String>(); - private RadixNode<String> normalNode = new RadixNode<String>(); - - @BeforeMethod - public void setUp(){ - rootNode.setKey(""); - rootNode.setValues(new HashSet<String>(Arrays.asList("root"))); - - normalNode.setKey("/data/cas/"); - normalNode.setValues(new HashSet<String>(Arrays.asList("CAS Project"))); - - } - - - @Test - public void testMatchingWithRoot(){ - String inputKey = "/data/cas/"; - Assert.assertEquals(rootNode.getMatchLength(inputKey), 0); - } - - @Test - public void testEmptyMatchingWithRoot(){ - String inputKey = ""; - Assert.assertEquals(rootNode.getMatchLength(inputKey), 0); - } - - @Test - public void testNullMatchingWithRoot(){ - Assert.assertEquals(rootNode.getMatchLength(null), 0); - } - - @Test - public void testDistinctStringMatching(){ - String inputKey = "data/cas"; - Assert.assertEquals(normalNode.getMatchLength(inputKey), 0); - } - - @Test - public void testSameStringMatching(){ - String inputKey = "/data/cas"; - Assert.assertEquals(normalNode.getMatchLength(inputKey), 9); - } - - @Test - public void testNullStringMatching(){ - Assert.assertEquals(normalNode.getMatchLength(null), 0); - } - - - @Test - public void testAddingDuplicateValues() { - rootNode.addValue("root"); - Assert.assertEquals(rootNode.getValues().size(), 1); - } - - @Test - public void testAddMultipleValues() { - normalNode.addValue("data"); - Assert.assertTrue(normalNode.containsValue("data")); - Assert.assertTrue(normalNode.containsValue("CAS Project")); - } - - @Test - public void testMatchInput() { - RadixNode<String> node = new RadixNode<String>(); - - FalconRadixUtils.INodeAlgorithm matcher = new FalconRadixUtils.FeedRegexAlgorithm(); - node.setKey("/data/cas/projects/${YEAR}/${MONTH}/${DAY}"); - Assert.assertTrue(node.matches("/data/cas/projects/2014/09/09", matcher)); - Assert.assertFalse(node.matches("/data/cas/projects/20140909", matcher)); - Assert.assertFalse(node.matches("/data/2014/projects/2014/09/09", matcher)); - Assert.assertFalse(node.matches("/data/2014/projects/2014/09/", matcher)); - Assert.assertFalse(node.matches("/data/cas/projects/2014/09/09trail", matcher)); - Assert.assertFalse(node.matches("/data/cas/projects/2014/09/09/", matcher)); - Assert.assertFalse(node.matches("/data/cas/projects/2014/09/", matcher)); - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/RadixTreeTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/RadixTreeTest.java b/common/src/test/java/org/apache/falcon/util/RadixTreeTest.java deleted file mode 100644 index e8b0e5b..0000000 --- a/common/src/test/java/org/apache/falcon/util/RadixTreeTest.java +++ /dev/null @@ -1,322 +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 - * - * 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.util; - -import org.apache.falcon.entity.store.FeedPathStore; -import org.apache.falcon.entity.v0.feed.LocationType; -import org.apache.falcon.resource.FeedLookupResult; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.List; - -/** - * Tests for Radix Tree. - */ -public class RadixTreeTest { - - private RadixTree<String> tree; - private FalconRadixUtils.INodeAlgorithm regexAlgorithm = new FalconRadixUtils.FeedRegexAlgorithm(); - - @BeforeMethod - public void setUp() { - tree = new RadixTree<String>(); - tree.insert("key1", "value1"); - tree.insert("key2", "value2"); - tree.insert("random", "random"); - } - - @AfterMethod - public void reset() { - tree = null; - } - - @Test - public void testInsertAtRootTest() { - FeedPathStore<String> tree2 = new RadixTree<String>(); - tree2.insert("/data/cas/projects/dwh/", "dwh"); - Assert.assertEquals(tree2.find("/data/cas/projects/dwh/").size(), 1); - Assert.assertTrue(tree2.find("/data/cas/projects/dwh/").contains("dwh")); - - } - - - @Test - public void testDuplicateKeyInsert() { - tree.insert("duplicatekey", "value1"); - tree.insert("duplicatekey", "value2"); - Assert.assertEquals(tree.find("duplicatekey").size(), 2); - Assert.assertTrue(tree.find("duplicatekey").contains("value1")); - Assert.assertTrue(tree.find("duplicatekey").contains("value2")); - } - - @Test - public void testGetNextCandidate() { - tree.insert("/projects/userplatform/${YEAR}-${MONTH}-${DAY}", "feed1"); - tree.insert("/projects/userplatform/another", "feed2"); - Collection<String> result = tree.find("/projects/userplatform/another"); - Assert.assertTrue(result.contains("feed2")); - - result = tree.find("/projects/userplatform/2014-07-07", regexAlgorithm); - Assert.assertTrue(result.contains("feed1")); - } - - @Test - public void testNoOverlap() { - tree.insert("water", "No Overlap"); - Assert.assertEquals(tree.getSize(), 4); - } - - @Test - public void testInputKeySubset() { - tree.insert("rand", "Input Subset"); - Assert.assertEquals(tree.getSize(), 4); - - } - - @Test - public void testInputKeySuperset() { - tree.insert("randomiser", "Input Superset"); - Assert.assertEquals(tree.getSize(), 4); - } - - - @Test - public void testInputKeyPathStyle() { - tree.insert("/data/cas/projects/", "path"); - Assert.assertEquals(tree.getSize(), 4); - Assert.assertTrue(tree.find("/data/cas/projects/").contains("path")); - } - - - // Tests for find String - @Test - public void testSubstringPathFind() { - tree.insert("/data/cas/projects/rtbd/", "rtbd"); - tree.insert("/data/cas/projects/dwh/", "dwh"); - Assert.assertEquals(tree.getSize(), 5); - Assert.assertTrue(tree.find("/data/cas/projects/rtbd/").contains("rtbd")); - Assert.assertTrue(tree.find("/data/cas/projects/dwh/").contains("dwh")); - Assert.assertNull(tree.find("/data/cas/projects/")); - } - - @Test - public void testStringSplitFind() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - Assert.assertTrue(tree.find("rand").contains("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertTrue(tree.find("randomizer").contains("randomizer")); - - } - - //Tests for find using regular expression - @Test - public void testFindUsingRegex() { - tree.insert("/data/cas/${YEAR}/", "rtbd"); - Assert.assertTrue(tree.find("/data/cas/2014/", regexAlgorithm).contains("rtbd")); - Assert.assertNull(tree.find("/data/cas/", regexAlgorithm)); - Assert.assertNull(tree.find("/data/cas/2014/09", regexAlgorithm)); - Assert.assertNull(tree.find("/data/cas/${YEAR}/", regexAlgorithm)); - - tree.insert("/data/cas/${YEAR}/colo", "local"); - tree.insert("/data/cas/${YEAR}/colo", "duplicate-local"); - Assert.assertNull(tree.find("/data/cas/${YEAR}/", regexAlgorithm)); - Assert.assertNull(tree.find("/data/cas/${YEAR}/colo", regexAlgorithm)); - Assert.assertNull(tree.find("/data/cas/", regexAlgorithm)); - Assert.assertTrue(tree.find("/data/cas/2014/", regexAlgorithm).contains("rtbd")); - Assert.assertTrue(tree.find("/data/cas/2014/colo", regexAlgorithm).contains("local")); - Assert.assertTrue(tree.find("/data/cas/2014/colo", regexAlgorithm).contains("duplicate-local")); - - - } - - // Tests for delete method - @Test - public void testDeleteChildOfTerminal() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - Assert.assertTrue(tree.delete("randomizer", "randomizer")); - Assert.assertNull(tree.find("randomizer")); - Assert.assertTrue(tree.find("random").contains("random")); - } - - @Test - public void testMarkingNonTerminal() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - tree.delete("rand", "rand"); - Assert.assertNull(tree.find("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertTrue(tree.find("randomizer").contains("randomizer")); - } - - @Test - public void testDoubleDelete() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - Assert.assertTrue(tree.delete("rand", "rand")); - Assert.assertFalse(tree.delete("rand", "rand")); - Assert.assertNull(tree.find("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertTrue(tree.find("randomizer").contains("randomizer")); - } - - @Test - public void testChildCompactionDelete() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - Assert.assertTrue(tree.delete("random", "random")); - Assert.assertNull(tree.find("random")); - Assert.assertTrue(tree.find("rand").contains("rand")); - Assert.assertTrue(tree.find("randomizer").contains("randomizer")); - Assert.assertEquals(tree.getSize(), 4); - } - - @Test - public void testParentCompactionDelete() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - Assert.assertTrue(tree.delete("randomizer", "randomizer")); - Assert.assertNull(tree.find("randomizer")); - Assert.assertTrue(tree.find("rand").contains("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertEquals(tree.getSize(), 4); - - } - - @Test - public void testSequencesOfDelete() { - tree.insert("rand", "rand"); - tree.insert("randomizer", "randomizer"); - - Assert.assertTrue(tree.delete("randomizer", "randomizer")); - Assert.assertNull(tree.find("randomizer")); - Assert.assertTrue(tree.find("rand").contains("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertEquals(tree.getSize(), 4); - - Assert.assertTrue(tree.delete("rand", "rand")); - Assert.assertNull(tree.find("rand")); - Assert.assertTrue(tree.find("random").contains("random")); - Assert.assertEquals(tree.getSize(), 3); - - Assert.assertTrue(tree.delete("random", "random")); - Assert.assertNull(tree.find("random")); - Assert.assertEquals(tree.getSize(), 2); - - } - - @Test - public void testRootNotCompactedInDelete() { - Assert.assertTrue(tree.delete("random", "random")); - Assert.assertTrue(tree.delete("key2", "value2")); - tree.insert("water", "water"); - Assert.assertTrue(tree.find("water").contains("water")); - } - - @Test - public void testDeleteFromListAndChildren() { - //check that a delete of a key with multiple values and children is handled - tree.insert("keyWithManyValuesAndChild", "value1"); - tree.insert("keyWithManyValuesAndChild", "value2"); - tree.insert("keyWithManyValuesAndChildren", "childValue"); - Assert.assertTrue(tree.delete("keyWithManyValuesAndChild", "value1")); - } - - @Test - public void testDeleteNonExistent() { - Assert.assertFalse(tree.delete("zzz", "zzz")); - } - - @Test - public void testDeleteSubstring() { - Assert.assertFalse(tree.delete("ke", "ke")); - } - - @Test - public void testDeleteNonTerminal() { - Assert.assertFalse(tree.delete("key", "key")); - } - - - @Test - public void testDeleteBlankOrEmptyOrNullString(){ - Assert.assertFalse(tree.delete("", "")); - Assert.assertFalse(tree.delete(" ", " ")); - Assert.assertFalse(tree.delete(null, null)); - } - - @Test - public void testAllSuffixForFirstLevelKey() { - tree.insert("key123", "Key was key123"); - tree.insert("key124", "Key was key124"); - List<String> result = tree.findSuffixChildren("key", 2); - Assert.assertEquals(result.size(), 2); - Assert.assertTrue(result.contains("1")); - Assert.assertTrue(result.contains("2")); - } - - @Test - public void testAllSuffixForNestedLevelKey() { - tree.insert("key123", "Key was key123"); - tree.insert("key124", "Key was key124"); - Assert.assertEquals(tree.findSuffixChildren("key1", 2).size(), 1); - Assert.assertEquals(tree.findSuffixChildren("key1", 2).get(0), "2"); - } - - @Test - public void testFeedPropertiesEquals() { - FeedLookupResult.FeedProperties f1 = new FeedLookupResult.FeedProperties("feed", - LocationType.DATA, "cluster"); - FeedLookupResult.FeedProperties f1Copy = new FeedLookupResult.FeedProperties("feed", - LocationType.DATA, "cluster"); - FeedLookupResult.FeedProperties f3 = new FeedLookupResult.FeedProperties("anotherFeed", - LocationType.DATA, "cluster"); - FeedLookupResult.FeedProperties f4 = new FeedLookupResult.FeedProperties("feed", - LocationType.STATS, "cluster"); - FeedLookupResult.FeedProperties f5 = new FeedLookupResult.FeedProperties("feed", - LocationType.DATA, "anotherCluster"); - - Assert.assertTrue(f1.equals(f1Copy)); - Assert.assertFalse(f1.equals(f3)); - Assert.assertFalse(f1.equals(f4)); - Assert.assertFalse(f1.equals(f5)); - - } - - @Test - public void testMultipleValues(){ - tree.insert("keyWithMultipleValues", "value1"); - tree.insert("keyWithMultipleValues", "value2"); - Assert.assertEquals(tree.find("keyWithMultipleValues").size(), 2); - Assert.assertTrue(tree.find("keyWithMultipleValues").contains("value1")); - Assert.assertTrue(tree.find("keyWithMultipleValues").contains("value2")); - - tree.delete("keyWithMultipleValues", "value1"); - Assert.assertTrue(tree.find("keyWithMultipleValues").contains("value2")); - Assert.assertFalse(tree.find("keyWithMultipleValues").contains("value1")); - - tree.delete("keyWithMultipleValues", "value2"); - Assert.assertNull(tree.find("keyWithMultipleValues")); - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/common/src/test/java/org/apache/falcon/util/ReflectionUtilsTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/falcon/util/ReflectionUtilsTest.java b/common/src/test/java/org/apache/falcon/util/ReflectionUtilsTest.java deleted file mode 100644 index bc0bce0..0000000 --- a/common/src/test/java/org/apache/falcon/util/ReflectionUtilsTest.java +++ /dev/null @@ -1,49 +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 - * - * 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.util; - -import org.apache.falcon.FalconException; -import org.apache.falcon.entity.parser.ClusterEntityParser; -import org.testng.Assert; -import org.testng.annotations.Test; - -/** - * Tests ReflectionUtils. - */ -@Test -public class ReflectionUtilsTest { - public void testGetInstance() throws FalconException { - //with 1 arg constructor, arg null - Object e = ReflectionUtils.getInstanceByClassName("org.apache.falcon.FalconException", Throwable.class, null); - Assert.assertTrue(e instanceof FalconException); - - //with 1 arg constructor, arg not null - e = ReflectionUtils.getInstanceByClassName("org.apache.falcon.FalconException", Throwable.class, - new Throwable()); - Assert.assertTrue(e instanceof FalconException); - - //no constructor, using get() method - e = ReflectionUtils.getInstanceByClassName("org.apache.falcon.util.StartupProperties"); - Assert.assertTrue(e instanceof StartupProperties); - - //with empty constructor - e = ReflectionUtils.getInstanceByClassName("org.apache.falcon.entity.parser.ClusterEntityParser"); - Assert.assertTrue(e instanceof ClusterEntityParser); - } -}
