### Question:
CompatibilityCheckStage extends AbstractBaseStage { @Override public void process(ClusterEvent event) throws Exception { HelixManager manager = event.getAttribute(AttributeName.helixmanager.name()); BaseControllerDataProvider cache = event.getAttribute(AttributeName.ControllerDataProvider.name()); if (manager == null || cache == null) { throw new StageException("Missing attributes in event:" + event + ". Requires HelixManager | DataCache"); } HelixManagerProperties properties = manager.getProperties(); Map<String, LiveInstance> liveInstanceMap = cache.getLiveInstances(); for (LiveInstance liveInstance : liveInstanceMap.values()) { String participantVersion = liveInstance.getHelixVersion(); if (!properties.isParticipantCompatible(participantVersion)) { String errorMsg = "incompatible participant. pipeline will not continue. " + "controller: " + manager.getInstanceName() + ", controllerVersion: " + properties.getVersion() + ", minimumSupportedParticipantVersion: " + properties.getProperty("minimum_supported_version.participant") + ", participant: " + liveInstance.getInstanceName() + ", participantVersion: " + participantVersion; LogUtil.logError(LOG, event.getEventId(), errorMsg); throw new StageException(errorMsg); } } }  @Override void process(ClusterEvent event);  }### Answer:
@Test public void testCompatible() { prepare("1.0.0", "1.0.0", "0.4"); CompatibilityCheckStage stage = new CompatibilityCheckStage(); StageContext context = new StageContext(); stage.init(context); stage.preProcess(); try { stage.process(event); } catch (Exception e) { Assert.fail("Should not fail since versions are compatible", e); } stage.postProcess(); }
@Test public void testNullParticipantVersion() { prepare("0.4.0", null); CompatibilityCheckStage stage = new CompatibilityCheckStage(); StageContext context = new StageContext(); stage.init(context); stage.preProcess(); try { stage.process(event); } catch (Exception e) { Assert .fail("Should not fail since compatibility check will be skipped if participant version is null"); } stage.postProcess(); }
@Test public void testNullControllerVersion() { prepare(null, "0.4.0"); CompatibilityCheckStage stage = new CompatibilityCheckStage(); StageContext context = new StageContext(); stage.init(context); stage.preProcess(); try { stage.process(event); } catch (Exception e) { Assert .fail("Should not fail since compatibility check will be skipped if controller version is null"); } stage.postProcess(); }
@Test public void testIncompatible() { prepare("0.6.1-incubating-SNAPSHOT", "0.3.4", "0.4"); CompatibilityCheckStage stage = new CompatibilityCheckStage(); StageContext context = new StageContext(); stage.init(context); stage.preProcess(); try { stage.process(event); Assert .fail("Should fail since participant version is less than the minimum participant version supported by controller"); } catch (Exception e) { } stage.postProcess(); }