flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject git commit: Reeenable tryLocalExecution() test in ClientTest
Date Thu, 26 Jun 2014 09:03:44 GMT
Repository: incubator-flink
Updated Branches:
  refs/heads/master 69589fa90 -> 20fdcfb49


Reeenable tryLocalExecution() test in ClientTest


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/20fdcfb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/20fdcfb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/20fdcfb4

Branch: refs/heads/master
Commit: 20fdcfb49d827b8f8848b380fb3fd982790378ab
Parents: 69589fa
Author: uce <u.celebi@fu-berlin.de>
Authored: Thu Jun 26 11:03:21 2014 +0200
Committer: uce <u.celebi@fu-berlin.de>
Committed: Thu Jun 26 11:03:21 2014 +0200

----------------------------------------------------------------------
 .../stratosphere/client/program/ClientTest.java | 146 +++++++++----------
 1 file changed, 66 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/20fdcfb4/stratosphere-clients/src/test/java/eu/stratosphere/client/program/ClientTest.java
----------------------------------------------------------------------
diff --git a/stratosphere-clients/src/test/java/eu/stratosphere/client/program/ClientTest.java
b/stratosphere-clients/src/test/java/eu/stratosphere/client/program/ClientTest.java
index a948706..fecc117 100644
--- a/stratosphere-clients/src/test/java/eu/stratosphere/client/program/ClientTest.java
+++ b/stratosphere-clients/src/test/java/eu/stratosphere/client/program/ClientTest.java
@@ -12,23 +12,9 @@
  **********************************************************************************************************************/
 package eu.stratosphere.client.program;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-import static org.powermock.api.mockito.PowerMockito.whenNew;
-
-import java.io.IOException;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
+import eu.stratosphere.api.common.InvalidProgramException;
 import eu.stratosphere.api.common.Plan;
+import eu.stratosphere.api.java.ExecutionEnvironment;
 import eu.stratosphere.compiler.DataStatistics;
 import eu.stratosphere.compiler.PactCompiler;
 import eu.stratosphere.compiler.costs.CostEstimator;
@@ -40,107 +26,107 @@ import eu.stratosphere.nephele.client.AbstractJobResult.ReturnCode;
 import eu.stratosphere.nephele.client.JobClient;
 import eu.stratosphere.nephele.client.JobSubmissionResult;
 import eu.stratosphere.nephele.jobgraph.JobGraph;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
+import java.io.IOException;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.doAnswer;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
 
 
 /**
  * Simple and maybe stupid test to check the {@link Client} class.
- * However, the use of mocks can be copied copied easily from this example.
- *
  */
 @RunWith(PowerMockRunner.class)
 @PrepareForTest(Client.class)
 public class ClientTest {
 
-	@Mock
-	Configuration configMock;
-
-	@Mock
-	PackagedProgram program;
-	@Mock
-	JobWithJars planWithJarsMock;
-	@Mock
-	Plan planMock;
-	
-	@Mock
-	PactCompiler compilerMock;
-	@Mock
-	OptimizedPlan optimizedPlanMock;
-	
-	@Mock
-	NepheleJobGraphGenerator generatorMock;
-	@Mock
-	JobGraph jobGraphMock;
-
-	@Mock
-	JobClient jobClientMock;
-	@Mock
-	JobSubmissionResult jobSubmissionResultMock;
-	
+	@Mock Configuration configMock;
+	@Mock PackagedProgram program;
+	@Mock JobWithJars planWithJarsMock;
+	@Mock Plan planMock;
+	@Mock PactCompiler compilerMock;
+	@Mock OptimizedPlan optimizedPlanMock;
+	@Mock NepheleJobGraphGenerator generatorMock;
+	@Mock JobGraph jobGraphMock;
+	@Mock JobClient jobClientMock;
+	@Mock JobSubmissionResult jobSubmissionResultMock;
+
 	@Before
-	public void setUp() throws Exception
-	{
+	public void setUp() throws Exception {
 		initMocks(this);
-		
+
 		when(configMock.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, null)).thenReturn("localhost");
 		when(configMock.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT)).thenReturn(6123);
-		
+
 		when(planMock.getJobName()).thenReturn("MockPlan");
 //		when(mockJarFile.getAbsolutePath()).thenReturn("mockFilePath");
-		
+
 		when(program.getPlanWithJars()).thenReturn(planWithJarsMock);
 		when(planWithJarsMock.getPlan()).thenReturn(planMock);
-		
+
 		whenNew(PactCompiler.class).withArguments(any(DataStatistics.class), any(CostEstimator.class)).thenReturn(this.compilerMock);
 		when(compilerMock.compile(planMock)).thenReturn(optimizedPlanMock);
-		
+
 		whenNew(NepheleJobGraphGenerator.class).withNoArguments().thenReturn(generatorMock);
 		when(generatorMock.compileJobGraph(optimizedPlanMock)).thenReturn(jobGraphMock);
-		
+
 		whenNew(JobClient.class).withArguments(any(JobGraph.class), any(Configuration.class)).thenReturn(this.jobClientMock);
-		
+
 		when(this.jobClientMock.submitJob()).thenReturn(jobSubmissionResultMock);
 	}
-	
+
 	@Test
-	public void shouldSubmitToJobClient() throws ProgramInvocationException, IOException
-	{
+	public void shouldSubmitToJobClient() throws ProgramInvocationException, IOException {
 		when(jobSubmissionResultMock.getReturnCode()).thenReturn(ReturnCode.SUCCESS);
-		
+
 		Client out = new Client(configMock);
 		out.run(program.getPlanWithJars(), -1, false);
 		program.deleteExtractedLibraries();
-		
+
 		verify(this.compilerMock, times(1)).compile(planMock);
 		verify(this.generatorMock, times(1)).compileJobGraph(optimizedPlanMock);
 		verify(this.jobClientMock, times(1)).submitJob();
 	}
-	
-	/**
-	 * @throws Exception
-	 */
-	@Test(expected=ProgramInvocationException.class)
-	public void shouldThrowException() throws Exception
-	{
+
+	@Test(expected = ProgramInvocationException.class)
+	public void shouldThrowException() throws Exception {
 		when(jobSubmissionResultMock.getReturnCode()).thenReturn(ReturnCode.ERROR);
-		
+
 		Client out = new Client(configMock);
 		out.run(program.getPlanWithJars(), -1, false);
 		program.deleteExtractedLibraries();
-		
+
 		verify(this.jobClientMock).submitJob();
 	}
-	
-//
-//	@Test(expected=InvalidProgramException.class)
-//	public void tryLocalExecution() throws Exception {
-//		new Client(configMock);
-//		LocalExecutor.execute(planMock);
-//	}
-//	
-//	@Test(expected=InvalidProgramException.class)
-//	public void tryLocalEnvironmentExecution() throws Exception {
-//		new Client(configMock);
-//		new LocalEnvironment();
-//	}
-}
\ No newline at end of file
+
+	@Test(expected = InvalidProgramException.class)
+	public void tryLocalExecution() throws Exception {
+		PackagedProgram packagedProgramMock = mock(PackagedProgram.class);
+
+		when(packagedProgramMock.isUsingInteractiveMode()).thenReturn(true);
+
+		doAnswer(new Answer<Void>() {
+			@Override
+			public Void answer(InvocationOnMock invocation) throws Throwable {
+				ExecutionEnvironment.createLocalEnvironment();
+				return null;
+			}
+		}).when(packagedProgramMock).invokeInteractiveModeForExecution();
+
+		new Client(configMock).run(packagedProgramMock, 1, true);
+	}
+}


Mime
View raw message