|
47 | 47 | import org.apache.hadoop.yarn.event.Dispatcher; |
48 | 48 | import org.apache.hadoop.yarn.event.EventHandler; |
49 | 49 | import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; |
| 50 | +import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore; |
50 | 51 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; |
51 | 52 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; |
52 | 53 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; |
@@ -398,6 +399,57 @@ public void testHAWithRMHostName() throws Exception { |
398 | 399 | innerTestHAWithRMHostName(true); |
399 | 400 | } |
400 | 401 |
|
| 402 | + @Test(timeout = 30000) |
| 403 | + public void testFailoverWhenTransitionToActiveThrowException() |
| 404 | + throws Exception { |
| 405 | + configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false); |
| 406 | + Configuration conf = new YarnConfiguration(configuration); |
| 407 | + |
| 408 | + MemoryRMStateStore memStore = new MemoryRMStateStore() { |
| 409 | + int count = 0; |
| 410 | + |
| 411 | + @Override |
| 412 | + public synchronized void startInternal() throws Exception { |
| 413 | + // first time throw exception |
| 414 | + if (count++ == 0) { |
| 415 | + throw new Exception("Session Expired"); |
| 416 | + } |
| 417 | + } |
| 418 | + }; |
| 419 | + // start RM |
| 420 | + memStore.init(conf); |
| 421 | + |
| 422 | + rm = new MockRM(conf, memStore); |
| 423 | + rm.init(conf); |
| 424 | + StateChangeRequestInfo requestInfo = |
| 425 | + new StateChangeRequestInfo( |
| 426 | + HAServiceProtocol.RequestSource.REQUEST_BY_USER); |
| 427 | + |
| 428 | + assertEquals(STATE_ERR, HAServiceState.INITIALIZING, rm.adminService |
| 429 | + .getServiceStatus().getState()); |
| 430 | + assertFalse("RM is ready to become active before being started", |
| 431 | + rm.adminService.getServiceStatus().isReadyToBecomeActive()); |
| 432 | + checkMonitorHealth(); |
| 433 | + |
| 434 | + rm.start(); |
| 435 | + checkMonitorHealth(); |
| 436 | + checkStandbyRMFunctionality(); |
| 437 | + |
| 438 | + // 2. Try Transition to active, throw exception |
| 439 | + try { |
| 440 | + rm.adminService.transitionToActive(requestInfo); |
| 441 | + Assert.fail("Transitioned to Active should throw exception."); |
| 442 | + } catch (Exception e) { |
| 443 | + assertTrue("Error when transitioning to Active mode".contains(e |
| 444 | + .getMessage())); |
| 445 | + } |
| 446 | + |
| 447 | + // 3. Transition to active, success |
| 448 | + rm.adminService.transitionToActive(requestInfo); |
| 449 | + checkMonitorHealth(); |
| 450 | + checkActiveRMFunctionality(); |
| 451 | + } |
| 452 | + |
401 | 453 | public void innerTestHAWithRMHostName(boolean includeBindHost) { |
402 | 454 | //this is run two times, with and without a bind host configured |
403 | 455 | if (includeBindHost) { |
|
0 commit comments