@Test public void updateVersion() throws VersionException, ChannelNotFoundException { final RedisDataStore store = newRedisDataStore(); final Channel channel = newChannel2(); store.saveChannel(channel); final String channelId = store.updateVersion(channel.getEndpointToken(), 2L); assertThat(channelId, equalTo(channel.getChannelId())); }
@Override public String updateVersion(final String endpointToken, final long newVersion) throws VersionException, ChannelNotFoundException { final Jedis jedis = jedisPool.getResource(); try { jedis.watch(endpointToken); final String versionString = jedis.get(endpointToken); if (versionString == null) { throw channelNotFoundException(endpointToken); } final long currentVersion = Long.valueOf(versionString); if (newVersion <= currentVersion) { throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]"); } final Transaction tx = jedis.multi(); tx.set(endpointToken, String.valueOf(newVersion)); tx.exec(); logger.debug(tokenLookupKey(endpointToken)); return jedis.get(tokenLookupKey(endpointToken)); } finally { jedisPool.returnResource(jedis); } }
RedisDataStore implements DataStore { @Override public String updateVersion(final String endpointToken, final long newVersion) throws VersionException, ChannelNotFoundException { final Jedis jedis = jedisPool.getResource(); try { jedis.watch(endpointToken); final String versionString = jedis.get(endpointToken); if (versionString == null) { throw channelNotFoundException(endpointToken); } final long currentVersion = Long.valueOf(versionString); if (newVersion <= currentVersion) { throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]"); } final Transaction tx = jedis.multi(); tx.set(endpointToken, String.valueOf(newVersion)); tx.exec(); logger.debug(tokenLookupKey(endpointToken)); return jedis.get(tokenLookupKey(endpointToken)); } finally { jedisPool.returnResource(jedis); } } }
RedisDataStore implements DataStore { @Override public String updateVersion(final String endpointToken, final long newVersion) throws VersionException, ChannelNotFoundException { final Jedis jedis = jedisPool.getResource(); try { jedis.watch(endpointToken); final String versionString = jedis.get(endpointToken); if (versionString == null) { throw channelNotFoundException(endpointToken); } final long currentVersion = Long.valueOf(versionString); if (newVersion <= currentVersion) { throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]"); } final Transaction tx = jedis.multi(); tx.set(endpointToken, String.valueOf(newVersion)); tx.exec(); logger.debug(tokenLookupKey(endpointToken)); return jedis.get(tokenLookupKey(endpointToken)); } finally { jedisPool.returnResource(jedis); } } RedisDataStore(final String host, final int port); }
RedisDataStore implements DataStore { @Override public String updateVersion(final String endpointToken, final long newVersion) throws VersionException, ChannelNotFoundException { final Jedis jedis = jedisPool.getResource(); try { jedis.watch(endpointToken); final String versionString = jedis.get(endpointToken); if (versionString == null) { throw channelNotFoundException(endpointToken); } final long currentVersion = Long.valueOf(versionString); if (newVersion <= currentVersion) { throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]"); } final Transaction tx = jedis.multi(); tx.set(endpointToken, String.valueOf(newVersion)); tx.exec(); logger.debug(tokenLookupKey(endpointToken)); return jedis.get(tokenLookupKey(endpointToken)); } finally { jedisPool.returnResource(jedis); } } RedisDataStore(final String host, final int port); @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel channel); @Override void removeChannels(final Set<String> channelIds); @Override Channel getChannel(final String channelId); @Override Set<String> getChannelIds(final String uaid); @Override void removeChannels(final String uaid); @Override String updateVersion(final String endpointToken, final long newVersion); @Override String saveUnacknowledged(final String channelId, final long version); @Override Set<Ack> getUnacknowledged(final String uaid); @Override Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acks); }
RedisDataStore implements DataStore { @Override public String updateVersion(final String endpointToken, final long newVersion) throws VersionException, ChannelNotFoundException { final Jedis jedis = jedisPool.getResource(); try { jedis.watch(endpointToken); final String versionString = jedis.get(endpointToken); if (versionString == null) { throw channelNotFoundException(endpointToken); } final long currentVersion = Long.valueOf(versionString); if (newVersion <= currentVersion) { throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]"); } final Transaction tx = jedis.multi(); tx.set(endpointToken, String.valueOf(newVersion)); tx.exec(); logger.debug(tokenLookupKey(endpointToken)); return jedis.get(tokenLookupKey(endpointToken)); } finally { jedisPool.returnResource(jedis); } } RedisDataStore(final String host, final int port); @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel channel); @Override void removeChannels(final Set<String> channelIds); @Override Channel getChannel(final String channelId); @Override Set<String> getChannelIds(final String uaid); @Override void removeChannels(final String uaid); @Override String updateVersion(final String endpointToken, final long newVersion); @Override String saveUnacknowledged(final String channelId, final long version); @Override Set<Ack> getUnacknowledged(final String uaid); @Override Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acks);  }