@Test public void testDeadToLiveTranistion() { LiveState state = new LiveState(); CellState result = state.nextState(StateTestUtils.getCellWithNLiveAndMDeadNebhours(3, 0, false)); assertEquals(state, result); }
public void onMessage(Jedis j, String channel, String message) { synchronized (j) { if ("property".equals(channel)) { // Called when Redis publish a property update. String propertyName = message; IProperty property = this.localState.getHierarchy().getProperty(propertyName); String value = j.get(propertyName); if (value != null) { property.setValue(value); } else { property.clearValue(); } String link = j.get(propertyName + "#link"); if (link != null) { property.setLink(link); } else { property.clearLink(); } } else if ("contest".equals(channel)) { if (REDIS_CONTEST_SYNC) { // Called when Redis publish a contest update. String[] keys = message.split("\\.", 4); assert (keys.length == 4); assert (keys[0].equals("contest")); ContestId contestId = new ContestId(keys[1], Long.valueOf(keys[2])); Set<String> fields = j.smembers(message + ".fields"); String type = j.get(message + ".type"); AttrsUpdateEventImpl e = new AttrsUpdateEventImpl(0, type); for (String field : fields) { e.setProperty(field, j.get(message + "." + field)); } // DebugTrace.trace(e.toString()); localState.getContest(contestId).attrsUpdated(e); } } } }
public void connect() { redis = new Jedis(redisShardInfo); redis.connect(); localState.addListeners(this); spawnSubscriptionThread(); synchronized (redis) { for (String s : redis.keys("live.*")) { // TODO: check prefix onMessage("property", s); // emulate received messages for all keys } if (REDIS_CONTEST_SYNC) { Set<String> contests = redis.smembers("contests"); for (String contest : contests) { List<String> events = redis.lrange(String.format("%s.events", contest), 0, -1); for (String event : events) { // don't these events have to be sorted??? onMessage("contest", String.format("%s.%s", contest, event)); } } } } }