@Override public void before() throws Exception { super.before(); clusterClient = createMiniClusterClient(); executionEnvironment = new TestEnvironment(getMiniCluster(), getNumberSlots(), false); executionEnvironment.setAsContext(); TestStreamEnvironment.setAsContext(getMiniCluster(), getNumberSlots()); }
@After public void teardownEnvironment() { switch(mode) { case CLUSTER: case CLUSTER_OBJECT_REUSE: TestEnvironment.unsetAsContext(); break; case COLLECTION: CollectionTestEnvironment.unsetAsContext(); break; } }
@Override public String getExecutionPlan() throws Exception { OptimizedPlan op = compileProgram("unused"); PlanJSONDumpGenerator jsonGen = new PlanJSONDumpGenerator(); return jsonGen.getOptimizerPlanAsJSON(op); }
public void setAsContext() { ExecutionEnvironmentFactory factory = new ExecutionEnvironmentFactory() { @Override public ExecutionEnvironment createExecutionEnvironment() { lastEnv = new TestEnvironment(jobExecutor, getParallelism(), getConfig().isObjectReuseEnabled()); return lastEnv; } }; initializeContextEnvironment(factory); }
@Override public ExecutionEnvironment createExecutionEnvironment() { lastEnv = new TestEnvironment(jobExecutor, getParallelism(), getConfig().isObjectReuseEnabled()); return lastEnv; } };
public TestEnvironment( JobExecutor jobExecutor, int parallelism, boolean isObjectReuseEnabled, Collection<Path> jarFiles, Collection<URL> classPaths) { this.jobExecutor = Preconditions.checkNotNull(jobExecutor); this.jarFiles = Preconditions.checkNotNull(jarFiles); this.classPaths = Preconditions.checkNotNull(classPaths); setParallelism(parallelism); // disabled to improve build time getConfig().setCodeAnalysisMode(CodeAnalysisMode.DISABLE); if (isObjectReuseEnabled) { getConfig().enableObjectReuse(); } else { getConfig().disableObjectReuse(); } lastEnv = null; }
TestEnvironment env = new TestEnvironment(this.executor, this.parallelism, false); env.getConfig().enableObjectReuse(); env.setAsContext(); this.latestExecutionResult = env.getLastJobExecutionResult(); TestEnvironment.unsetAsContext();
/** * Sets the current {@link ExecutionEnvironment} to be a {@link TestEnvironment}. The test * environment executes the given jobs on a Flink mini cluster with the given default * parallelism and the additional jar files and class paths. * * @param jobExecutor The executor to run the jobs on * @param parallelism The default parallelism */ public static void setAsContext(final JobExecutor jobExecutor, final int parallelism) { setAsContext( jobExecutor, parallelism, Collections.emptyList(), Collections.emptyList()); }
@Before public void setupEnvironment() { TestEnvironment testEnvironment; switch(mode){ case CLUSTER: // This only works because of the quirks we built in the TestEnvironment. // We should refactor this in the future!!! testEnvironment = miniClusterResource.getTestEnvironment(); testEnvironment.getConfig().disableObjectReuse(); testEnvironment.setAsContext(); break; case CLUSTER_OBJECT_REUSE: // This only works because of the quirks we built in the TestEnvironment. // We should refactor this in the future!!! testEnvironment = miniClusterResource.getTestEnvironment(); testEnvironment.getConfig().enableObjectReuse(); testEnvironment.setAsContext(); break; case COLLECTION: new CollectionTestEnvironment().setAsContext(); break; } }
env.getConfig().enableObjectReuse(); this.latestExecutionResult = env.getLastJobExecutionResult();
@Override public ExecutionEnvironment createExecutionEnvironment() { return new TestEnvironment( jobExecutor, parallelism, false, jarFiles, classPaths ); } };
public static void unsetAsContext() { resetContextEnvironment(); } }
private OptimizedPlan compileProgram(String jobName) { Plan p = createProgramPlan(jobName); Optimizer pc = new Optimizer(new DataStatistics(), new Configuration()); return pc.compile(p); }
@Override public JobExecutionResult getLastJobExecutionResult() { if (lastEnv == null) { return lastJobExecutionResult; } else { return lastEnv.getLastJobExecutionResult(); } }
TestEnvironment env = new TestEnvironment(this.executor, this.parallelism, false); env.getConfig().disableObjectReuse(); env.setAsContext(); this.latestExecutionResult = env.getLastJobExecutionResult(); TestEnvironment.unsetAsContext();
@Override public ExecutionEnvironment createExecutionEnvironment() { lastEnv = new TestEnvironment(jobExecutor, getParallelism(), getConfig().isObjectReuseEnabled()); return lastEnv; } };
/** * Sets the current {@link ExecutionEnvironment} to be a {@link TestEnvironment}. The test * environment executes the given jobs on a Flink mini cluster with the given default * parallelism and the additional jar files and class paths. * * @param jobExecutor The executor to run the jobs on * @param parallelism The default parallelism * @param jarFiles Additional jar files to execute the job with * @param classPaths Additional class paths to execute the job with */ public static void setAsContext( final JobExecutor jobExecutor, final int parallelism, final Collection<Path> jarFiles, final Collection<URL> classPaths) { ExecutionEnvironmentFactory factory = new ExecutionEnvironmentFactory() { @Override public ExecutionEnvironment createExecutionEnvironment() { return new TestEnvironment( jobExecutor, parallelism, false, jarFiles, classPaths ); } }; initializeContextEnvironment(factory); }
@Test public void testExternalProgram() throws Exception { TestEnvironment.setAsContext( MINI_CLUSTER, PARALLELISM, Collections.singleton(new Path(JAR_FILE)), Collections.emptyList()); String testData = getClass().getResource(TEST_DATA_FILE).toString(); PackagedProgram program = new PackagedProgram(new File(JAR_FILE), new String[]{testData}); program.invokeInteractiveModeForExecution(); } }
@Before public void setupEnvironment() { TestEnvironment testEnvironment; switch(mode){ case CLUSTER: // This only works because of the quirks we built in the TestEnvironment. // We should refactor this in the future!!! testEnvironment = miniClusterResource.getTestEnvironment(); testEnvironment.getConfig().disableObjectReuse(); testEnvironment.setAsContext(); break; case CLUSTER_OBJECT_REUSE: // This only works because of the quirks we built in the TestEnvironment. // We should refactor this in the future!!! testEnvironment = miniClusterResource.getTestEnvironment(); testEnvironment.getConfig().enableObjectReuse(); testEnvironment.setAsContext(); break; case COLLECTION: new CollectionTestEnvironment().setAsContext(); break; } }
public TestEnvironment( JobExecutor jobExecutor, int parallelism, boolean isObjectReuseEnabled, Collection<Path> jarFiles, Collection<URL> classPaths) { this.jobExecutor = Preconditions.checkNotNull(jobExecutor); this.jarFiles = Preconditions.checkNotNull(jarFiles); this.classPaths = Preconditions.checkNotNull(classPaths); setParallelism(parallelism); // disabled to improve build time getConfig().setCodeAnalysisMode(CodeAnalysisMode.DISABLE); if (isObjectReuseEnabled) { getConfig().enableObjectReuse(); } else { getConfig().disableObjectReuse(); } lastEnv = null; }