@Test public void saveUnacknowledged() throws ChannelNotFoundException { final InMemoryDataStore store = new InMemoryDataStore(); final String uaid = UUIDUtil.newUAID(); final String channelId1 = UUID.randomUUID().toString(); store.saveChannel(mockChannel(uaid, channelId1, 1, "endpointToken")); store.saveUnacknowledged(channelId1, 10L); final Set<Ack> acks = store.getUnacknowledged(uaid); assertThat(acks, hasItem(ack(channelId1, 10L))); }
@Override public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException { checkNotNull(channelId, "channelId"); checkNotNull(version, "version"); final Channel channel = channels.get(channelId); if (channel == null) { throw new ChannelNotFoundException("Could not find channel", channelId); } final String uaid = channel.getUAID(); final Set<Ack> newAcks = Collections.newSetFromMap(new ConcurrentHashMap<Ack, Boolean>()); newAcks.add(new AckImpl(channelId, version)); while (true) { final Set<Ack> currentAcks = unacked.get(uaid); if (currentAcks == null) { final Set<Ack> previous = unacked.putIfAbsent(uaid, newAcks); if (previous != null) { newAcks.addAll(previous); if (unacked.replace(uaid, previous, newAcks)) { break; } } } else { newAcks.addAll(currentAcks); if (unacked.replace(uaid, currentAcks, newAcks)) { break; } } } return uaid; }
InMemoryDataStore implements DataStore { @Override public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException { checkNotNull(channelId, "channelId"); checkNotNull(version, "version"); final Channel channel = channels.get(channelId); if (channel == null) { throw new ChannelNotFoundException("Could not find channel", channelId); } final String uaid = channel.getUAID(); final Set<Ack> newAcks = Collections.newSetFromMap(new ConcurrentHashMap<Ack, Boolean>()); newAcks.add(new AckImpl(channelId, version)); while (true) { final Set<Ack> currentAcks = unacked.get(uaid); if (currentAcks == null) { final Set<Ack> previous = unacked.putIfAbsent(uaid, newAcks); if (previous != null) { newAcks.addAll(previous); if (unacked.replace(uaid, previous, newAcks)) { break; } } } else { newAcks.addAll(currentAcks); if (unacked.replace(uaid, currentAcks, newAcks)) { break; } } } return uaid; } }
InMemoryDataStore implements DataStore { @Override public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException { checkNotNull(channelId, "channelId"); checkNotNull(version, "version"); final Channel channel = channels.get(channelId); if (channel == null) { throw new ChannelNotFoundException("Could not find channel", channelId); } final String uaid = channel.getUAID(); final Set<Ack> newAcks = Collections.newSetFromMap(new ConcurrentHashMap<Ack, Boolean>()); newAcks.add(new AckImpl(channelId, version)); while (true) { final Set<Ack> currentAcks = unacked.get(uaid); if (currentAcks == null) { final Set<Ack> previous = unacked.putIfAbsent(uaid, newAcks); if (previous != null) { newAcks.addAll(previous); if (unacked.replace(uaid, previous, newAcks)) { break; } } } else { newAcks.addAll(currentAcks); if (unacked.replace(uaid, currentAcks, newAcks)) { break; } } } return uaid; }  }
InMemoryDataStore implements DataStore { @Override public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException { checkNotNull(channelId, "channelId"); checkNotNull(version, "version"); final Channel channel = channels.get(channelId); if (channel == null) { throw new ChannelNotFoundException("Could not find channel", channelId); } final String uaid = channel.getUAID(); final Set<Ack> newAcks = Collections.newSetFromMap(new ConcurrentHashMap<Ack, Boolean>()); newAcks.add(new AckImpl(channelId, version)); while (true) { final Set<Ack> currentAcks = unacked.get(uaid); if (currentAcks == null) { final Set<Ack> previous = unacked.putIfAbsent(uaid, newAcks); if (previous != null) { newAcks.addAll(previous); if (unacked.replace(uaid, previous, newAcks)) { break; } } } else { newAcks.addAll(currentAcks); if (unacked.replace(uaid, currentAcks, newAcks)) { break; } } } return uaid; }  @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel ch); @Override Channel getChannel(final String channelId); @Override void removeChannels(final String uaid); @Override void removeChannels(final Set<String> channelIds); @Override Set<String> getChannelIds(final String uaid); @Override String updateVersion(final String endpointToken, final long version); @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> acked); }
InMemoryDataStore implements DataStore { @Override public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException { checkNotNull(channelId, "channelId"); checkNotNull(version, "version"); final Channel channel = channels.get(channelId); if (channel == null) { throw new ChannelNotFoundException("Could not find channel", channelId); } final String uaid = channel.getUAID(); final Set<Ack> newAcks = Collections.newSetFromMap(new ConcurrentHashMap<Ack, Boolean>()); newAcks.add(new AckImpl(channelId, version)); while (true) { final Set<Ack> currentAcks = unacked.get(uaid); if (currentAcks == null) { final Set<Ack> previous = unacked.putIfAbsent(uaid, newAcks); if (previous != null) { newAcks.addAll(previous); if (unacked.replace(uaid, previous, newAcks)) { break; } } } else { newAcks.addAll(currentAcks); if (unacked.replace(uaid, currentAcks, newAcks)) { break; } } } return uaid; }  @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel ch); @Override Channel getChannel(final String channelId); @Override void removeChannels(final String uaid); @Override void removeChannels(final Set<String> channelIds); @Override Set<String> getChannelIds(final String uaid); @Override String updateVersion(final String endpointToken, final long version); @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> acked);  }