Return-Path: X-Original-To: apmail-falcon-commits-archive@minotaur.apache.org Delivered-To: apmail-falcon-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 83B5010BB1 for ; Tue, 20 Oct 2015 12:09:59 +0000 (UTC) Received: (qmail 35247 invoked by uid 500); 20 Oct 2015 12:09:59 -0000 Delivered-To: apmail-falcon-commits-archive@falcon.apache.org Received: (qmail 35160 invoked by uid 500); 20 Oct 2015 12:09:59 -0000 Mailing-List: contact commits-help@falcon.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@falcon.apache.org Delivered-To: mailing list commits@falcon.apache.org Received: (qmail 35142 invoked by uid 99); 20 Oct 2015 12:09:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Oct 2015 12:09:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EB340DFE1D; Tue, 20 Oct 2015 12:09:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pallavi@apache.org To: commits@falcon.apache.org Date: Tue, 20 Oct 2015 12:09:58 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/6] falcon git commit: FALCON-1213 Base framework of the native scheduler Repository: falcon Updated Branches: refs/heads/master 9e6d5a6c5 -> a0911bd82 http://git-wip-us.apache.org/repos/asf/falcon/blob/4175c54a/scheduler/src/test/java/org/apache/falcon/state/InstanceStateServiceTest.java ---------------------------------------------------------------------- diff --git a/scheduler/src/test/java/org/apache/falcon/state/InstanceStateServiceTest.java b/scheduler/src/test/java/org/apache/falcon/state/InstanceStateServiceTest.java new file mode 100644 index 0000000..d27ac7e --- /dev/null +++ b/scheduler/src/test/java/org/apache/falcon/state/InstanceStateServiceTest.java @@ -0,0 +1,138 @@ +/** + * 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.state; + +import org.apache.falcon.FalconException; +import org.apache.falcon.entity.v0.process.Process; +import org.apache.falcon.exception.InvalidStateTransitionException; +import org.apache.falcon.exception.StateStoreException; +import org.apache.falcon.execution.ProcessExecutionInstance; +import org.apache.falcon.state.store.AbstractStateStore; +import org.apache.falcon.state.store.InMemoryStateStore; +import org.joda.time.DateTime; +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Tests the state changes of an instance. + */ +public class InstanceStateServiceTest { + + private InstanceStateChangeHandler listener = Mockito.mock(InstanceStateChangeHandler.class); + private ProcessExecutionInstance mockInstance; + + @BeforeMethod + public void setup() { + Process testProcess = new Process(); + testProcess.setName("test"); + // Setup new mocks so we can verify the no. of invocations + mockInstance = Mockito.mock(ProcessExecutionInstance.class); + Mockito.when(mockInstance.getEntity()).thenReturn(testProcess); + Mockito.when(mockInstance.getInstanceTime()).thenReturn(DateTime.now()); + Mockito.when(mockInstance.getCluster()).thenReturn("testCluster"); + } + + @AfterMethod + public void tearDown() { + ((InMemoryStateStore) AbstractStateStore.get()).clear(); + } + + // Tests an entity instance's lifecycle : Trigger -> waiting -> ready -> running + // -> suspendAll -> resumeAll -> success + @Test + public void testLifeCycle() throws FalconException { + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.TRIGGER, listener); + InstanceState instanceFromStore = AbstractStateStore.get() + .getExecutionInstance(new ID(mockInstance)); + Mockito.verify(listener).onTrigger(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.WAITING)); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.CONDITIONS_MET, listener); + Mockito.verify(listener).onConditionsMet(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.READY)); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.SCHEDULE, listener); + Mockito.verify(listener).onSchedule(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.RUNNING)); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.SUSPEND, listener); + Mockito.verify(listener).onSuspend(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.SUSPENDED)); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.RESUME_RUNNING, listener); + Mockito.verify(listener).onResume(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.RUNNING)); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.SUCCEED, listener); + Mockito.verify(listener).onSuccess(mockInstance); + Assert.assertTrue(instanceFromStore.getCurrentState().equals(InstanceState.STATE.SUCCEEDED)); + Assert.assertEquals(AbstractStateStore.get().getAllEntities().size(), 0); + } + + @Test + public void testInvalidTransitions() throws FalconException { + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.TRIGGER, listener); + try { + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.SCHEDULE, listener); + Assert.fail("Exception expected"); + } catch (InvalidStateTransitionException e) { + // Do nothing + } + + // Resume an instance that is not suspended + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.CONDITIONS_MET, listener); + try { + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.RESUME_READY, listener); + Assert.fail("Exception expected"); + } catch (InvalidStateTransitionException e) { + // Do nothing + } + + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.SCHEDULE, listener); + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.FAIL, listener); + + // Attempt killing a completed instance + try { + StateService.get().handleStateChange(mockInstance, InstanceState.EVENT.KILL, listener); + Assert.fail("Exception expected"); + } catch (InvalidStateTransitionException e) { + // Do nothing + } + } + + @Test(dataProvider = "state_and_events") + public void testIdempotency(InstanceState.STATE state, InstanceState.EVENT event) + throws InvalidStateTransitionException, StateStoreException { + InstanceState instanceState = new InstanceState(mockInstance).setCurrentState(state); + instanceState.nextTransition(event); + Assert.assertEquals(instanceState.getCurrentState(), state); + } + + @DataProvider(name = "state_and_events") + public Object[][] stateAndEvents() { + return new Object[][] { + {InstanceState.STATE.WAITING, InstanceState.EVENT.TRIGGER}, + {InstanceState.STATE.READY, InstanceState.EVENT.CONDITIONS_MET}, + {InstanceState.STATE.TIMED_OUT, InstanceState.EVENT.TIME_OUT}, + {InstanceState.STATE.RUNNING, InstanceState.EVENT.SCHEDULE}, + {InstanceState.STATE.SUSPENDED, InstanceState.EVENT.SUSPEND}, + {InstanceState.STATE.KILLED, InstanceState.EVENT.KILL}, + {InstanceState.STATE.SUCCEEDED, InstanceState.EVENT.SUCCEED}, + {InstanceState.STATE.FAILED, InstanceState.EVENT.FAIL}, + }; + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/4175c54a/scheduler/src/test/resources/config/cluster/cluster-0.1.xml ---------------------------------------------------------------------- diff --git a/scheduler/src/test/resources/config/cluster/cluster-0.1.xml b/scheduler/src/test/resources/config/cluster/cluster-0.1.xml new file mode 100644 index 0000000..223cbc6 --- /dev/null +++ b/scheduler/src/test/resources/config/cluster/cluster-0.1.xml @@ -0,0 +1,43 @@ + + + + + consumer=consumer@xyz.com, owner=producer@xyz.com, department=forecasting + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/falcon/blob/4175c54a/scheduler/src/test/resources/config/feed/feed-0.1.xml ---------------------------------------------------------------------- diff --git a/scheduler/src/test/resources/config/feed/feed-0.1.xml b/scheduler/src/test/resources/config/feed/feed-0.1.xml new file mode 100644 index 0000000..25daf7d --- /dev/null +++ b/scheduler/src/test/resources/config/feed/feed-0.1.xml @@ -0,0 +1,57 @@ + + + + + + + + + online,bi + _SUCCESS + + hours(1) + + UTC + + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/falcon/blob/4175c54a/scheduler/src/test/resources/config/process/process-0.1.xml ---------------------------------------------------------------------- diff --git a/scheduler/src/test/resources/config/process/process-0.1.xml b/scheduler/src/test/resources/config/process/process-0.1.xml new file mode 100644 index 0000000..deeb554 --- /dev/null +++ b/scheduler/src/test/resources/config/process/process-0.1.xml @@ -0,0 +1,54 @@ + + + + consumer=consumer@xyz.com, owner=producer@xyz.com, department=forecasting + testPipeline,dataReplication_Pipeline + + + + + + 1 + LIFO + minutes(1) + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/falcon/blob/4175c54a/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index da12d3a..8891e5f 100644 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -119,6 +119,12 @@ org.apache.falcon + falcon-scheduler + ${project.version} + + + + org.apache.falcon falcon-retention