use of akka.testkit.JavaTestKit in project flink by apache.
the class ResourceManagerTest method testTriggerReconnect.
@Test
public void testTriggerReconnect() {
new JavaTestKit(system) {
{
new Within(duration("10 seconds")) {
@Override
protected void run() {
// set a long timeout for lookups such that the test fails in case of timeouts
Configuration shortTimeoutConfig = config.clone();
shortTimeoutConfig.setString(ConfigConstants.AKKA_LOOKUP_TIMEOUT, "99999 s");
fakeJobManager = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
resourceManager = TestingUtils.createResourceManager(system, fakeJobManager.actor(), shortTimeoutConfig);
// wait for registration message
RegisterResourceManager msg = expectMsgClass(RegisterResourceManager.class);
// all went well
resourceManager.tell(new RegisterResourceManagerSuccessful(fakeJobManager.actor(), Collections.<ResourceID>emptyList()), fakeJobManager);
// force a reconnect
resourceManager.tell(new TriggerRegistrationAtJobManager(fakeJobManager.actor()), fakeJobManager);
// new registration attempt should come in
expectMsgClass(RegisterResourceManager.class);
}
};
}
};
}
use of akka.testkit.JavaTestKit in project flink by apache.
the class StackTraceSampleCoordinatorITCase method testTaskClearedWhileSampling.
/**
* Tests that a cleared task is answered with a partial success response.
*/
@Test
public void testTaskClearedWhileSampling() throws Exception {
new JavaTestKit(testActorSystem) {
{
final FiniteDuration deadline = new FiniteDuration(60, TimeUnit.SECONDS);
// The JobGraph
final JobGraph jobGraph = new JobGraph();
final int parallelism = 1;
final JobVertex task = new JobVertex("Task");
task.setInvokableClass(BlockingNoOpInvokable.class);
task.setParallelism(parallelism);
jobGraph.addVertex(task);
ActorGateway jobManger = null;
ActorGateway taskManager = null;
try {
jobManger = TestingUtils.createJobManager(testActorSystem, TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), new Configuration());
final Configuration config = new Configuration();
config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, parallelism);
taskManager = TestingUtils.createTaskManager(testActorSystem, jobManger, config, true, true);
final ActorGateway jm = jobManger;
new Within(deadline) {
@Override
protected void run() {
try {
ActorGateway testActor = new AkkaActorGateway(getTestActor(), null);
int maxAttempts = 10;
int sleepTime = 100;
for (int i = 0; i < maxAttempts; i++, sleepTime *= 2) {
// Submit the job and wait until it is running
JobClient.submitJobDetached(jm, config, jobGraph, deadline, ClassLoader.getSystemClassLoader());
jm.tell(new WaitForAllVerticesToBeRunning(jobGraph.getJobID()), testActor);
expectMsgEquals(new AllVerticesRunning(jobGraph.getJobID()));
// Get the ExecutionGraph
jm.tell(new RequestExecutionGraph(jobGraph.getJobID()), testActor);
ExecutionGraphFound executionGraphResponse = expectMsgClass(ExecutionGraphFound.class);
ExecutionGraph executionGraph = (ExecutionGraph) executionGraphResponse.executionGraph();
ExecutionJobVertex vertex = executionGraph.getJobVertex(task.getID());
StackTraceSampleCoordinator coordinator = new StackTraceSampleCoordinator(testActorSystem.dispatcher(), 60000);
Future<StackTraceSample> sampleFuture = coordinator.triggerStackTraceSample(vertex.getTaskVertices(), // sampling.
21474700 * 100, Time.milliseconds(10L), 0);
// Wait before cancelling so that some samples
// are actually taken.
Thread.sleep(sleepTime);
// Cancel job
scala.concurrent.Future<?> removeFuture = jm.ask(new TestingJobManagerMessages.NotifyWhenJobRemoved(jobGraph.getJobID()), remaining());
jm.tell(new JobManagerMessages.CancelJob(jobGraph.getJobID()));
try {
// Throws Exception on failure
sampleFuture.get(remaining().toMillis(), TimeUnit.MILLISECONDS);
// partial result.
break;
} catch (Throwable t) {
// We were too fast in cancelling the job.
// Fall through and retry.
} finally {
Await.ready(removeFuture, remaining());
}
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
};
} finally {
TestingUtils.stopActor(jobManger);
TestingUtils.stopActor(taskManager);
}
}
};
}
use of akka.testkit.JavaTestKit in project flink by apache.
the class ClusterShutdownITCase method testClusterShutdownWithResourceManager.
/**
* Tests a faked cluster shutdown procedure with the ResourceManager.
*/
@Test
public void testClusterShutdownWithResourceManager() {
new JavaTestKit(system) {
{
new Within(duration("30 seconds")) {
@Override
protected void run() {
ActorGateway me = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
// start job manager which doesn't shutdown the actor system
ActorGateway jobManager = TestingUtils.createJobManager(system, TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), config, "jobmanager2");
// Tell the JobManager to inform us of shutdown actions
jobManager.tell(TestingMessages.getNotifyOfComponentShutdown(), me);
// Register a TaskManager
ActorGateway taskManager = TestingUtils.createTaskManager(system, jobManager, config, true, true);
// Tell the TaskManager to inform us of TaskManager shutdowns
taskManager.tell(TestingMessages.getNotifyOfComponentShutdown(), me);
// Start resource manager and let it register
ActorGateway resourceManager = TestingUtils.createResourceManager(system, jobManager.actor(), config);
// Tell the ResourceManager to inform us of ResourceManager shutdowns
resourceManager.tell(TestingMessages.getNotifyOfComponentShutdown(), me);
// notify about a resource manager registration at the job manager
resourceManager.tell(new TestingResourceManager.NotifyWhenResourceManagerConnected(), me);
// Wait for resource manager
expectMsgEquals(Acknowledge.get());
// Shutdown cluster with resource manager connected
jobManager.tell(new StopCluster(ApplicationStatus.SUCCEEDED, "Shutting down."), me);
expectMsgAllOf(new TestingMessages.ComponentShutdown(taskManager.actor()), new TestingMessages.ComponentShutdown(jobManager.actor()), new TestingMessages.ComponentShutdown(resourceManager.actor()), StopClusterSuccessful.getInstance());
}
};
}
};
}
use of akka.testkit.JavaTestKit in project flink by apache.
the class ResourceManagerITCase method testResourceManagerReconciliation.
/**
* Tests whether the resource manager connects and reconciles existing task managers.
*/
@Test
public void testResourceManagerReconciliation() {
new JavaTestKit(system) {
{
new Within(duration("10 seconds")) {
@Override
protected void run() {
ActorGateway jobManager = TestingUtils.createJobManager(system, TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), config, "ReconciliationTest");
ActorGateway me = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
// !! no resource manager started !!
ResourceID resourceID = ResourceID.generate();
TaskManagerLocation location = mock(TaskManagerLocation.class);
when(location.getResourceID()).thenReturn(resourceID);
HardwareDescription resourceProfile = HardwareDescription.extractFromSystem(1_000_000);
jobManager.tell(new RegistrationMessages.RegisterTaskManager(resourceID, location, resourceProfile, 1), me);
expectMsgClass(RegistrationMessages.AcknowledgeRegistration.class);
// now start the resource manager
ActorGateway resourceManager = TestingUtils.createResourceManager(system, jobManager.actor(), config);
// register at testing job manager to receive a message once a resource manager registers
resourceManager.tell(new TestingResourceManager.NotifyWhenResourceManagerConnected(), me);
// Wait for resource manager
expectMsgEquals(Acknowledge.get());
// check if we registered the task manager resource
resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), me);
TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
assertEquals(1, reply.resources.size());
assertTrue(reply.resources.contains(resourceID));
}
};
}
};
}
use of akka.testkit.JavaTestKit in project flink by apache.
the class ResourceManagerTest method testResourceFailureNotification.
/**
* Tests notification of JobManager about a failed resource.
*/
@Test
public void testResourceFailureNotification() {
new JavaTestKit(system) {
{
new Within(duration("10 seconds")) {
@Override
protected void run() {
fakeJobManager = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
resourceManager = TestingUtils.createResourceManager(system, fakeJobManager.actor(), config);
// register with JM
expectMsgClass(RegisterResourceManager.class);
resourceManager.tell(new RegisterResourceManagerSuccessful(fakeJobManager.actor(), Collections.<ResourceID>emptyList()), fakeJobManager);
ResourceID resourceID1 = ResourceID.generate();
ResourceID resourceID2 = ResourceID.generate();
// Send task manager registration
resourceManager.tell(new NotifyResourceStarted(resourceID1), fakeJobManager);
expectMsgClass(Acknowledge.class);
// Send task manager registration
resourceManager.tell(new NotifyResourceStarted(resourceID2), fakeJobManager);
expectMsgClass(Acknowledge.class);
// check for number registration of registered resources
resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
assertEquals(2, reply.resources.size());
assertTrue(reply.resources.contains(resourceID1));
assertTrue(reply.resources.contains(resourceID2));
// fail resources
resourceManager.tell(new TestingResourceManager.FailResource(resourceID1), fakeJobManager);
resourceManager.tell(new TestingResourceManager.FailResource(resourceID2), fakeJobManager);
ResourceRemoved answer = expectMsgClass(ResourceRemoved.class);
ResourceRemoved answer2 = expectMsgClass(ResourceRemoved.class);
assertEquals(resourceID1, answer.resourceId());
assertEquals(resourceID2, answer2.resourceId());
}
};
}
};
}
Aggregations