use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class ReportErrorTest method testReport.
@Test
public void testReport() {
final String topo = "topology";
final String comp = "component";
final Long port = new Long(8080);
final AtomicLong errorCount = new AtomicLong(0l);
WorkerTopologyContext context = mock(WorkerTopologyContext.class);
when(context.getThisWorkerPort()).thenReturn(port.intValue());
IStormClusterState state = mock(IStormClusterState.class);
doAnswer((invocation) -> errorCount.incrementAndGet()).when(state).reportError(eq(topo), eq(comp), any(String.class), eq(port), any(Throwable.class));
Map<String, Object> conf = new HashMap<>();
conf.put(Config.TOPOLOGY_ERROR_THROTTLE_INTERVAL_SECS, 10);
conf.put(Config.TOPOLOGY_MAX_ERROR_REPORT_PER_INTERVAL, 4);
try (SimulatedTime t = new SimulatedTime()) {
ReportError report = new ReportError(conf, state, topo, comp, context);
report.report(new RuntimeException("ERROR-1"));
assertEquals(1, errorCount.get());
report.report(new RuntimeException("ERROR-2"));
assertEquals(2, errorCount.get());
report.report(new RuntimeException("ERROR-3"));
assertEquals(3, errorCount.get());
report.report(new RuntimeException("ERROR-4"));
assertEquals(4, errorCount.get());
//Too fast not reported
report.report(new RuntimeException("ERROR-5"));
assertEquals(4, errorCount.get());
Time.advanceTime(9000);
report.report(new RuntimeException("ERROR-6"));
assertEquals(4, errorCount.get());
Time.advanceTime(2000);
report.report(new RuntimeException("ERROR-7"));
assertEquals(5, errorCount.get());
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SlotTest method testRunWithProfileActions.
@Test
public void testRunWithProfileActions() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
int port = 8080;
String cTopoId = "CURRENT";
List<ExecutorInfo> cExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment cAssignment = mkLocalAssignment(cTopoId, cExecList, mkWorkerResources(100.0, 100.0, 100.0));
Container cContainer = mock(Container.class);
//NOT going to timeout for a while
LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs() + 100);
when(cContainer.readHeartbeat()).thenReturn(chb, chb, chb, chb, chb, chb);
when(cContainer.runProfiling(any(ProfileRequest.class), anyBoolean())).thenReturn(true);
ILocalizer localizer = mock(ILocalizer.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
ISupervisor iSuper = mock(ISupervisor.class);
LocalState state = mock(LocalState.class);
StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
Set<TopoProfileAction> profileActions = new HashSet<>();
ProfileRequest request = new ProfileRequest();
request.set_action(ProfileAction.JPROFILE_STOP);
NodeInfo info = new NodeInfo();
info.set_node("localhost");
info.add_to_port(port);
request.set_nodeInfo(info);
//3 seconds from now
request.set_time_stamp(Time.currentTimeMillis() + 3000);
TopoProfileAction profile = new TopoProfileAction(cTopoId, request);
profileActions.add(profile);
Set<TopoProfileAction> expectedPending = new HashSet<>();
expectedPending.add(profile);
DynamicState dynamicState = new DynamicState(cAssignment, cContainer, cAssignment).withProfileActions(profileActions, Collections.<TopoProfileAction>emptySet());
DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
verify(cContainer).runProfiling(request, false);
assertEquals(expectedPending, nextState.pendingStopProfileActions);
assertEquals(expectedPending, nextState.profileActions);
assertTrue(Time.currentTimeMillis() > 1000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertEquals(expectedPending, nextState.pendingStopProfileActions);
assertEquals(expectedPending, nextState.profileActions);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertEquals(expectedPending, nextState.pendingStopProfileActions);
assertEquals(expectedPending, nextState.profileActions);
assertTrue(Time.currentTimeMillis() > 3000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
verify(cContainer).runProfiling(request, true);
assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.pendingStopProfileActions);
assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.profileActions);
assertTrue(Time.currentTimeMillis() > 4000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.pendingStopProfileActions);
assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.profileActions);
assertTrue(Time.currentTimeMillis() > 5000);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SlotTest method testLaunchContainerFromEmpty.
@Test
public void testLaunchContainerFromEmpty() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
int port = 8080;
String topoId = "NEW";
List<ExecutorInfo> execList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment newAssignment = mkLocalAssignment(topoId, execList, mkWorkerResources(100.0, 100.0, 100.0));
ILocalizer localizer = mock(ILocalizer.class);
Container container = mock(Container.class);
LocalState state = mock(LocalState.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
when(containerLauncher.launchContainer(port, newAssignment, state)).thenReturn(container);
LSWorkerHeartbeat hb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs());
when(container.readHeartbeat()).thenReturn(hb, hb);
@SuppressWarnings("unchecked") Future<Void> baseFuture = mock(Future.class);
when(localizer.requestDownloadBaseTopologyBlobs(newAssignment, port)).thenReturn(baseFuture);
@SuppressWarnings("unchecked") Future<Void> blobFuture = mock(Future.class);
when(localizer.requestDownloadTopologyBlobs(newAssignment, port)).thenReturn(blobFuture);
ISupervisor iSuper = mock(ISupervisor.class);
StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
DynamicState dynamicState = new DynamicState(null, null, null).withNewAssignment(newAssignment);
DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
verify(localizer).requestDownloadBaseTopologyBlobs(newAssignment, port);
assertEquals(MachineState.WAITING_FOR_BASIC_LOCALIZATION, nextState.state);
assertSame("pendingDownload not set properly", baseFuture, nextState.pendingDownload);
assertEquals(newAssignment, nextState.pendingLocalization);
assertEquals(0, Time.currentTimeMillis());
nextState = Slot.stateMachineStep(nextState, staticState);
verify(baseFuture).get(1000, TimeUnit.MILLISECONDS);
verify(localizer).requestDownloadTopologyBlobs(newAssignment, port);
assertEquals(MachineState.WAITING_FOR_BLOB_LOCALIZATION, nextState.state);
assertSame("pendingDownload not set properly", blobFuture, nextState.pendingDownload);
assertEquals(newAssignment, nextState.pendingLocalization);
assertEquals(0, Time.currentTimeMillis());
nextState = Slot.stateMachineStep(nextState, staticState);
verify(blobFuture).get(1000, TimeUnit.MILLISECONDS);
verify(containerLauncher).launchContainer(port, newAssignment, state);
assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(newAssignment, nextState.currentAssignment);
assertSame(container, nextState.container);
assertEquals(0, Time.currentTimeMillis());
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(newAssignment, nextState.currentAssignment);
assertSame(container, nextState.container);
assertEquals(0, Time.currentTimeMillis());
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(newAssignment, nextState.currentAssignment);
assertSame(container, nextState.container);
assertTrue(Time.currentTimeMillis() > 1000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(newAssignment, nextState.currentAssignment);
assertSame(container, nextState.container);
assertTrue(Time.currentTimeMillis() > 2000);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class SlotTest method testReschedule.
@Test
public void testReschedule() throws Exception {
try (SimulatedTime t = new SimulatedTime(1010)) {
int port = 8080;
String cTopoId = "CURRENT";
List<ExecutorInfo> cExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment cAssignment = mkLocalAssignment(cTopoId, cExecList, mkWorkerResources(100.0, 100.0, 100.0));
Container cContainer = mock(Container.class);
LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs());
when(cContainer.readHeartbeat()).thenReturn(chb);
when(cContainer.areAllProcessesDead()).thenReturn(false, true);
String nTopoId = "NEW";
List<ExecutorInfo> nExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
LocalAssignment nAssignment = mkLocalAssignment(nTopoId, nExecList, mkWorkerResources(100.0, 100.0, 100.0));
ILocalizer localizer = mock(ILocalizer.class);
Container nContainer = mock(Container.class);
LocalState state = mock(LocalState.class);
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
when(containerLauncher.launchContainer(port, nAssignment, state)).thenReturn(nContainer);
LSWorkerHeartbeat nhb = mkWorkerHB(nTopoId, 100, nExecList, Time.currentTimeSecs());
when(nContainer.readHeartbeat()).thenReturn(nhb, nhb);
@SuppressWarnings("unchecked") Future<Void> baseFuture = mock(Future.class);
when(localizer.requestDownloadBaseTopologyBlobs(nAssignment, port)).thenReturn(baseFuture);
@SuppressWarnings("unchecked") Future<Void> blobFuture = mock(Future.class);
when(localizer.requestDownloadTopologyBlobs(nAssignment, port)).thenReturn(blobFuture);
ISupervisor iSuper = mock(ISupervisor.class);
StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
DynamicState dynamicState = new DynamicState(cAssignment, cContainer, nAssignment);
DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
assertEquals(MachineState.KILL, nextState.state);
verify(cContainer).kill();
verify(localizer).requestDownloadBaseTopologyBlobs(nAssignment, port);
assertSame("pendingDownload not set properly", baseFuture, nextState.pendingDownload);
assertEquals(nAssignment, nextState.pendingLocalization);
assertTrue(Time.currentTimeMillis() > 1000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.KILL, nextState.state);
verify(cContainer).forceKill();
assertSame("pendingDownload not set properly", baseFuture, nextState.pendingDownload);
assertEquals(nAssignment, nextState.pendingLocalization);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.WAITING_FOR_BASIC_LOCALIZATION, nextState.state);
verify(cContainer).cleanUp();
verify(localizer).releaseSlotFor(cAssignment, port);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.WAITING_FOR_BLOB_LOCALIZATION, nextState.state);
verify(baseFuture).get(1000, TimeUnit.MILLISECONDS);
verify(localizer).requestDownloadTopologyBlobs(nAssignment, port);
assertSame("pendingDownload not set properly", blobFuture, nextState.pendingDownload);
assertEquals(nAssignment, nextState.pendingLocalization);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
verify(blobFuture).get(1000, TimeUnit.MILLISECONDS);
verify(containerLauncher).launchContainer(port, nAssignment, state);
assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(nAssignment, nextState.currentAssignment);
assertSame(nContainer, nextState.container);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(nAssignment, nextState.currentAssignment);
assertSame(nContainer, nextState.container);
assertTrue(Time.currentTimeMillis() > 2000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(nAssignment, nextState.currentAssignment);
assertSame(nContainer, nextState.container);
assertTrue(Time.currentTimeMillis() > 3000);
nextState = Slot.stateMachineStep(nextState, staticState);
assertEquals(MachineState.RUNNING, nextState.state);
assertSame("pendingDownload is not null", null, nextState.pendingDownload);
assertSame(null, nextState.pendingLocalization);
assertSame(nAssignment, nextState.currentAssignment);
assertSame(nContainer, nextState.container);
assertTrue(Time.currentTimeMillis() > 4000);
}
}
use of org.apache.storm.utils.Time.SimulatedTime in project storm by apache.
the class LogConfigManagerTest method testProcessRootLogLevelToDebugSetsLoggerAndTimeout.
@Test
public void testProcessRootLogLevelToDebugSetsLoggerAndTimeout() {
try (SimulatedTime t = new SimulatedTime()) {
LogConfig mockConfig = new LogConfig();
AtomicReference<TreeMap<String, LogLevel>> mockConfigAtom = new AtomicReference<>(null);
long inThirtySeconds = Time.currentTimeMillis() + 30_000;
mockConfig.put_to_named_logger_level("ROOT", ll("DEBUG", inThirtySeconds));
mockConfig.put_to_named_logger_level("my_debug_logger", ll("DEBUG", inThirtySeconds));
mockConfig.put_to_named_logger_level("my_info_logger", ll("INFO", inThirtySeconds));
mockConfig.put_to_named_logger_level("my_error_logger", ll("ERROR", inThirtySeconds));
LOG.info("Tests {}", mockConfigAtom.get());
LogConfigManager underTest = spy(new LogConfigManagerUnderTest(mockConfigAtom));
underTest.processLogConfigChange(mockConfig);
verify(underTest).setLoggerLevel(anyObject(), eq(""), eq("DEBUG"));
verify(underTest).setLoggerLevel(anyObject(), eq("my_debug_logger"), eq("DEBUG"));
verify(underTest).setLoggerLevel(anyObject(), eq("my_info_logger"), eq("INFO"));
verify(underTest).setLoggerLevel(anyObject(), eq("my_error_logger"), eq("ERROR"));
}
}
Aggregations