List of usage examples for org.apache.commons.compress.utils Sets newHashSet
public static <E> HashSet<E> newHashSet(@SuppressWarnings("unchecked") E... elements)
From source file:org.apache.bookkeeper.metadata.etcd.helpers.KeySetReaderTest.java
@Test public void testReadSingleKey() throws Exception { String key = RandomStringUtils.randomAlphabetic(16); ByteSequence keyBs = ByteSequence.fromString(key); try (KeySetReader<String> ksReader = new KeySetReader<>(etcdClient, BYTE_SEQUENCE_STRING_FUNCTION, keyBs, null)) {/*from ww w .j a v a 2 s . com*/ // key not exists Versioned<Set<String>> versionedKeys = FutureUtils.result(ksReader.read()); assertTrue("VersionedKeys : " + versionedKeys, ((LongVersion) versionedKeys.getVersion()).getLongVersion() > 0L); assertEquals(0, versionedKeys.getValue().size()); assertFalse(ksReader.isWatcherSet()); // keys should be cached assertEquals(versionedKeys, ksReader.getLocalValue()); // update a value String value = RandomStringUtils.randomAlphabetic(32); ByteSequence valueBs = ByteSequence.fromString(value); FutureUtils.result(etcdClient.getKVClient().put(keyBs, valueBs)); // update the value should not change local value assertEquals(versionedKeys, ksReader.getLocalValue()); // read the key again Versioned<Set<String>> newVersionedKey = FutureUtils.result(ksReader.read()); assertEquals(Occurred.AFTER, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(1, newVersionedKey.getValue().size()); assertEquals(Sets.newHashSet(key), newVersionedKey.getValue()); // local value should be changed assertEquals(newVersionedKey, ksReader.getLocalValue()); } }
From source file:org.apache.bookkeeper.metadata.etcd.helpers.KeySetReaderTest.java
@Test public void testWatchSingleKey() throws Exception { String key = RandomStringUtils.randomAlphabetic(16); ByteSequence keyBs = ByteSequence.fromString(key); KeySetReader<String> ksReader = null; try {//from ww w . ja v a2 s .c om ksReader = new KeySetReader<>(etcdClient, BYTE_SEQUENCE_STRING_FUNCTION, keyBs, null); LinkedBlockingQueue<Versioned<Set<String>>> notifications = new LinkedBlockingQueue<>(); Consumer<Versioned<Set<String>>> keyConsumer = consumeVersionedKeySet(notifications); // key not exists Versioned<Set<String>> versionedKeys = FutureUtils.result(ksReader.readAndWatch(keyConsumer)); assertTrue("VersionedKeys : " + versionedKeys, ((LongVersion) versionedKeys.getVersion()).getLongVersion() > 0L); assertEquals(0, versionedKeys.getValue().size()); assertTrue(ksReader.isWatcherSet()); // keys should be cached assertEquals(versionedKeys, ksReader.getLocalValue()); Versioned<Set<String>> newVersionedKey = notifications.take(); assertEquals(Occurred.CONCURRENTLY, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(versionedKeys, newVersionedKey); versionedKeys = newVersionedKey; // update a value String value = RandomStringUtils.randomAlphabetic(32); ByteSequence valueBs = ByteSequence.fromString(value); FutureUtils.result(etcdClient.getKVClient().put(keyBs, valueBs)); // we should get notified with updated key set newVersionedKey = notifications.take(); assertEquals(Occurred.AFTER, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(1, newVersionedKey.getValue().size()); assertEquals(Sets.newHashSet(key), newVersionedKey.getValue()); // local value should be changed assertEquals(newVersionedKey, ksReader.getLocalValue()); versionedKeys = newVersionedKey; // delete the key FutureUtils.result(etcdClient.getKVClient().delete(keyBs)); newVersionedKey = notifications.take(); assertEquals(Occurred.AFTER, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(0, newVersionedKey.getValue().size()); // local value should be changed assertEquals(newVersionedKey, ksReader.getLocalValue()); } finally { if (null != ksReader) { ksReader.close(); } } assertNotNull(ksReader); assertFalse(ksReader.isWatcherSet()); }
From source file:org.apache.bookkeeper.metadata.etcd.helpers.KeySetReaderTest.java
@Test public void testWatchSingleKeyWithTTL() throws Exception { String key = RandomStringUtils.randomAlphabetic(16); ByteSequence keyBs = ByteSequence.fromString(key); KeySetReader<String> ksReader = null; try {//from w ww. j a v a2 s.com ksReader = new KeySetReader<>(etcdClient, BYTE_SEQUENCE_STRING_FUNCTION, keyBs, null); LinkedBlockingQueue<Versioned<Set<String>>> notifications = new LinkedBlockingQueue<>(); Consumer<Versioned<Set<String>>> keyConsumer = consumeVersionedKeySet(notifications); // key not exists Versioned<Set<String>> versionedKeys = FutureUtils.result(ksReader.readAndWatch(keyConsumer)); assertTrue("VersionedKeys : " + versionedKeys, ((LongVersion) versionedKeys.getVersion()).getLongVersion() > 0L); assertEquals(0, versionedKeys.getValue().size()); assertTrue(ksReader.isWatcherSet()); // keys should be cached assertEquals(versionedKeys, ksReader.getLocalValue()); // no watch event should be issued Versioned<Set<String>> newVersionedKey = notifications.take(); assertEquals(Occurred.CONCURRENTLY, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(versionedKeys, newVersionedKey); versionedKeys = newVersionedKey; // create a key with ttl long leaseId = FutureUtils.result(etcdClient.getLeaseClient().grant(1)).getID(); String value = RandomStringUtils.randomAlphabetic(32); ByteSequence valueBs = ByteSequence.fromString(value); FutureUtils.result(etcdClient.getKVClient().put(keyBs, valueBs, PutOption.newBuilder().withLeaseId(leaseId).build())); // we should get notified with updated key set newVersionedKey = notifications.take(); assertEquals(Occurred.AFTER, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(1, newVersionedKey.getValue().size()); assertEquals(Sets.newHashSet(key), newVersionedKey.getValue()); // local value should be changed assertEquals(newVersionedKey, ksReader.getLocalValue()); versionedKeys = newVersionedKey; // the key will be deleted after TTL newVersionedKey = notifications.take(); assertEquals(Occurred.AFTER, newVersionedKey.getVersion().compare(versionedKeys.getVersion())); assertEquals(0, newVersionedKey.getValue().size()); // local value should be changed assertEquals(newVersionedKey, ksReader.getLocalValue()); } finally { if (null != ksReader) { ksReader.close(); } } assertNotNull(ksReader); assertFalse(ksReader.isWatcherSet()); }
From source file:org.testcontainers.couchbase.CouchbaseContainer.java
@Override public Set<Integer> getLivenessCheckPortNumbers() { return Sets.newHashSet(getMappedPort(REST)); }
From source file:org.xwiki.notifications.filters.watch.internal.DefaultWatchedEntitiesManager.java
private void handleEntity(WatchedEntityReference entity, DocumentReference user, boolean shouldBeWatched) throws NotificationException { // If the entity is already in the desired state, then we have nothing to do if (entity.isWatched(user) == shouldBeWatched) { return;/*from w ww. j ava 2s . c o m*/ } Iterator<NotificationFilterPreference> filterPreferences = getAllEventsFilterPreferences(user).iterator(); boolean thereIsAMatch = false; // Look if an existing filter match the entity while (filterPreferences.hasNext()) { NotificationFilterPreference notificationFilterPreference = filterPreferences.next(); if (entity.matchExactly(notificationFilterPreference)) { thereIsAMatch = true; if (notificationFilterPreference.getFilterType() == NotificationFilterType.INCLUSIVE && notificationFilterPreference.isEnabled() != shouldBeWatched) { enableOrDeleteFilter(shouldBeWatched, notificationFilterPreference); } else if (notificationFilterPreference.getFilterType() == NotificationFilterType.EXCLUSIVE && notificationFilterPreference.isEnabled() == shouldBeWatched) { enableOrDeleteFilter(!shouldBeWatched, notificationFilterPreference); } } } // But it might been still unwatched because of an other filter! if (!thereIsAMatch || entity.isWatched(user) != shouldBeWatched) { notificationFilterManager .saveFilterPreferences(Sets.newHashSet(createFilterPreference(entity, shouldBeWatched))); } }
From source file:org.xwiki.notifications.filters.watch.WatchedUserReference.java
@Override public boolean matchExactly(NotificationFilterPreference notificationFilterPreference) { return EventUserFilter.FILTER_NAME.equals(notificationFilterPreference.getFilterName()) && notificationFilterPreference.getProperties(NotificationFilterProperty.USER).contains(userId) && notificationFilterPreference.getFilterFormats() .containsAll(Sets.newHashSet(NotificationFormat.values())); }
From source file:org.xwiki.notifications.filters.watch.WatchedUserReference.java
@Override public NotificationFilterPreference createExclusiveFilterPreference() { DefaultNotificationFilterPreference filterPreference = new DefaultNotificationFilterPreference( Long.toString(new Date().getTime())); filterPreference.setEnabled(true);//from ww w. j ava 2 s. c om filterPreference.setFilterType(NotificationFilterType.EXCLUSIVE); filterPreference.setFilterName(EventUserFilter.FILTER_NAME); filterPreference.setNotificationFormats(Sets.newHashSet(NotificationFormat.values())); filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(false); // Properties Map<NotificationFilterProperty, List<String>> preferenceProperties = new HashMap<>(); filterPreference.setPreferenceProperties(preferenceProperties); preferenceProperties.put(NotificationFilterProperty.EVENT_TYPE, Collections.emptyList()); preferenceProperties.put(NotificationFilterProperty.USER, Collections.singletonList(userId)); return filterPreference; }