@Test public void updateRuleCacheTest() { final Experiment.ID EXPERIMENT_ID = Experiment.ID.newInstance(); Experiment experiment = Experiment.withID(EXPERIMENT_ID).withApplicationName(testApp).build(); experiment.setRule("state=CA"); final Rule RULE = new RuleBuilder().parseExpression(experiment.getRule()); experimentRuleCacheUpdateEnvelope = new ExperimentRuleCacheUpdateEnvelope(experiment.getRule(), ruleCache, EXPERIMENT_ID) { @Override public Rule getExperimentRule(String anyString) { return RULE; } }; Mockito.when(ruleCache.containsRule(experiment.getID())).thenReturn(false); experimentRuleCacheUpdateEnvelope.run(); Mockito.verify(ruleCache, Mockito.times(1)).setRule(experiment.getID(), RULE); Mockito.when(ruleCache.containsRule(EXPERIMENT_ID)).thenReturn(true); Mockito.when(ruleCache.getRule(EXPERIMENT_ID)).thenReturn(new RuleBuilder().parseExpression("a=b")); experimentRuleCacheUpdateEnvelope.run(); Mockito.verify(ruleCache, Mockito.times(2)).setRule(EXPERIMENT_ID, RULE); experimentRuleCacheUpdateEnvelope = new ExperimentRuleCacheUpdateEnvelope(null, ruleCache, EXPERIMENT_ID) { @Override public Rule getExperimentRule(String anyString) { return RULE; } }; experiment.setRule(null); Mockito.when(ruleCache.getRule(EXPERIMENT_ID)).thenReturn(RULE); experimentRuleCacheUpdateEnvelope.run(); Mockito.verify(ruleCache, Mockito.times(1)).setRule(EXPERIMENT_ID, null); }
@Override public void run() { try { if (!isEmpty(cassandraRuleString)) { Rule cassandraRule = getExperimentRule(cassandraRuleString); if (!ruleCache.containsRule(experimentID) || !cassandraRule.equals(ruleCache.getRule(experimentID))) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, cassandraRule); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + cassandraRule.getExpressionRepresentation()); } } else if (isEmpty(cassandraRuleString) && ruleCache.getRule(experimentID) != null) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, null); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + oldRule.getExpressionRepresentation() + " to null"); } } catch (Exception e) { LOGGER.warn("RuleCache update error on [" + cassandraRuleString + "] : ", e); } }
ExperimentRuleCacheUpdateEnvelope implements Runnable { @Override public void run() { try { if (!isEmpty(cassandraRuleString)) { Rule cassandraRule = getExperimentRule(cassandraRuleString); if (!ruleCache.containsRule(experimentID) || !cassandraRule.equals(ruleCache.getRule(experimentID))) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, cassandraRule); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + cassandraRule.getExpressionRepresentation()); } } else if (isEmpty(cassandraRuleString) && ruleCache.getRule(experimentID) != null) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, null); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + oldRule.getExpressionRepresentation() + " to null"); } } catch (Exception e) { LOGGER.warn("RuleCache update error on [" + cassandraRuleString + "] : ", e); } } }
ExperimentRuleCacheUpdateEnvelope implements Runnable { @Override public void run() { try { if (!isEmpty(cassandraRuleString)) { Rule cassandraRule = getExperimentRule(cassandraRuleString); if (!ruleCache.containsRule(experimentID) || !cassandraRule.equals(ruleCache.getRule(experimentID))) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, cassandraRule); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + cassandraRule.getExpressionRepresentation()); } } else if (isEmpty(cassandraRuleString) && ruleCache.getRule(experimentID) != null) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, null); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + oldRule.getExpressionRepresentation() + " to null"); } } catch (Exception e) { LOGGER.warn("RuleCache update error on [" + cassandraRuleString + "] : ", e); } } ExperimentRuleCacheUpdateEnvelope(String cassandraRuleString, RuleCache ruleCache, Experiment.ID experimentID); }
ExperimentRuleCacheUpdateEnvelope implements Runnable { @Override public void run() { try { if (!isEmpty(cassandraRuleString)) { Rule cassandraRule = getExperimentRule(cassandraRuleString); if (!ruleCache.containsRule(experimentID) || !cassandraRule.equals(ruleCache.getRule(experimentID))) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, cassandraRule); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + cassandraRule.getExpressionRepresentation()); } } else if (isEmpty(cassandraRuleString) && ruleCache.getRule(experimentID) != null) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, null); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + oldRule.getExpressionRepresentation() + " to null"); } } catch (Exception e) { LOGGER.warn("RuleCache update error on [" + cassandraRuleString + "] : ", e); } } ExperimentRuleCacheUpdateEnvelope(String cassandraRuleString, RuleCache ruleCache, Experiment.ID experimentID); @Override void run(); }
ExperimentRuleCacheUpdateEnvelope implements Runnable { @Override public void run() { try { if (!isEmpty(cassandraRuleString)) { Rule cassandraRule = getExperimentRule(cassandraRuleString); if (!ruleCache.containsRule(experimentID) || !cassandraRule.equals(ruleCache.getRule(experimentID))) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, cassandraRule); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + cassandraRule.getExpressionRepresentation()); } } else if (isEmpty(cassandraRuleString) && ruleCache.getRule(experimentID) != null) { Rule oldRule = ruleCache.getRule(experimentID); ruleCache.setRule(experimentID, null); LOGGER.info(getUTCTime() + " Segmentation rule of " + experimentID + " updated from " + oldRule.getExpressionRepresentation() + " to null"); } } catch (Exception e) { LOGGER.warn("RuleCache update error on [" + cassandraRuleString + "] : ", e); } } ExperimentRuleCacheUpdateEnvelope(String cassandraRuleString, RuleCache ruleCache, Experiment.ID experimentID); @Override void run();  }