use of java.util.Collections.EMPTY_SET in project hedera-services by hashgraph.
the class HapiFileUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
Optional<Key> wacl = useBadlyEncodedWacl ? Optional.of(badlyEncodedWacl()) : (useEmptyWacl ? Optional.of(emptyWacl()) : newWaclKey.map(spec.registry()::getKey));
if (newContentsPath.isPresent()) {
newContents = Optional.of(ByteString.copyFrom(Files.toByteArray(new File(newContentsPath.get()))));
} else if (contentFn.isPresent()) {
newContents = Optional.of(contentFn.get().apply(spec));
} else if (propOverrides.isPresent() || propDeletions.isPresent()) {
if (propOverrides.isEmpty()) {
propOverrides = Optional.of(Collections.emptyMap());
}
ServicesConfigurationList defaults = readBaseProps(spec);
ServicesConfigurationList.Builder list = ServicesConfigurationList.newBuilder();
Map<String, String> overrides = propOverrides.get();
Map<String, String> defaultPairs = defaults.getNameValueList().stream().collect(Collectors.toMap(Setting::getName, Setting::getValue));
Set<String> keys = new HashSet<>();
defaults.getNameValueList().stream().map(Setting::getName).filter(key -> !propDeletions.orElse(EMPTY_SET).contains(key)).forEach(keys::add);
overrides.keySet().stream().forEach(keys::add);
keys.forEach(key -> {
if (overrides.containsKey(key)) {
list.addNameValue(asSetting(key, overrides.get(key)));
} else {
list.addNameValue(asSetting(key, defaultPairs.get(key)));
}
});
newContents = Optional.of(list.build().toByteString());
}
long nl = -1;
if (expiryExtension.isPresent()) {
try {
var oldExpiry = spec.registry().getTimestamp(file).getSeconds();
nl = oldExpiry - Instant.now().getEpochSecond() + expiryExtension.getAsLong();
} catch (Exception ignore) {
}
} else if (lifetimeSecs.isPresent()) {
nl = lifetimeSecs.get();
}
final OptionalLong newLifetime = (nl == -1) ? OptionalLong.empty() : OptionalLong.of(nl);
var fid = TxnUtils.asFileId(file, spec);
FileUpdateTransactionBody opBody = spec.txns().<FileUpdateTransactionBody, FileUpdateTransactionBody.Builder>body(FileUpdateTransactionBody.class, builder -> {
builder.setFileID(fid);
newMemo.ifPresent(s -> builder.setMemo(StringValue.newBuilder().setValue(s).build()));
wacl.ifPresent(k -> builder.setKeys(k.getKeyList()));
newContents.ifPresent(b -> builder.setContents(b));
newLifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
});
preUpdateCb.ifPresent(cb -> cb.accept(fid));
return builder -> builder.setFileUpdate(opBody);
}
use of java.util.Collections.EMPTY_SET in project camunda-bpm-platform by camunda.
the class DefaultDeploymentConfiguration method getDeploymentResources.
@Override
public Set<Resource> getDeploymentResources() {
final ResourceArrayPropertyEditor resolver = new ResourceArrayPropertyEditor();
try {
final String[] resourcePattern = camundaBpmProperties.getDeploymentResourcePattern();
logger.debug("resolving deployment resources for pattern {}", (Object[]) resourcePattern);
resolver.setValue(resourcePattern);
return Arrays.stream((Resource[]) resolver.getValue()).peek(resource -> logger.debug("processing deployment resource {}", resource)).filter(this::isFile).peek(resource -> logger.debug("added deployment resource {}", resource)).collect(Collectors.toSet());
} catch (final RuntimeException e) {
logger.error("unable to resolve resources", e);
}
return EMPTY_SET;
}
use of java.util.Collections.EMPTY_SET in project reactive-wizard by FortnoxAB.
the class HttpClientTest method shouldReportUnhealthyWhenConnectionCannotBeAcquiredBeforeTimeoutAndAfter10Attempts.
@Test
public void shouldReportUnhealthyWhenConnectionCannotBeAcquiredBeforeTimeoutAndAfter10Attempts() throws URISyntaxException {
HttpClientConfig httpClientConfig = new HttpClientConfig();
int port = 13337;
httpClientConfig.setUrl("http://localhost:" + port);
httpClientConfig.setMaxConnections(1);
httpClientConfig.setConnectionMaxIdleTimeInMs(10);
ReactorRxClientProvider reactorRxClientProvider = new ReactorRxClientProvider(httpClientConfig, healthRecorder);
HttpClient reactorHttpClient = new HttpClient(httpClientConfig, reactorRxClientProvider, new ObjectMapper(), new RequestParameterSerializers(), EMPTY_SET, requestLogger);
TestResource testResource = reactorHttpClient.create(TestResource.class);
// First ten should not cause the client to be unhealthy
range(1, 11).forEach(value -> testResource.postHello().test().awaitTerminalEvent());
assertThat(healthRecorder.isHealthy()).isTrue();
// but the eleventh should
testResource.postHello().test().awaitTerminalEvent();
assertThat(healthRecorder.isHealthy()).isFalse();
// And a successful connection should reset the healthRecorder to healthy again
DisposableServer server = HttpServer.create().port(port).handle((request, response) -> defer(() -> {
response.status(OK);
return Flux.empty();
})).bindNow();
try {
testResource.postHello().test().awaitTerminalEvent();
assertThat(healthRecorder.isHealthy()).isTrue();
} finally {
server.disposeNow();
}
// Sleep over the max idle time
try {
Thread.sleep(httpClientConfig.getConnectionMaxIdleTimeInMs() + 10);
} catch (InterruptedException e) {
e.printStackTrace();
}
// And should accept another 10 errors
range(1, 11).forEach(value -> testResource.postHello().test().awaitTerminalEvent());
assertThat(healthRecorder.isHealthy()).isTrue();
}
use of java.util.Collections.EMPTY_SET in project cache2k by cache2k.
the class CacheLoaderTest method testReloadAll.
@Test
public void testReloadAll() throws ExecutionException, InterruptedException {
AtomicInteger countLoad = new AtomicInteger();
Cache<Integer, Integer> c = target.cache(b -> b.loader(key -> countLoad.incrementAndGet()));
c.get(5);
assertThat(countLoad.get()).isEqualTo(1);
c.reloadAll(asList(5, 6)).get();
assertThat(countLoad.get()).isEqualTo(3);
c.reloadAll(asList(5, 6));
c.reloadAll(EMPTY_SET);
}
use of java.util.Collections.EMPTY_SET in project cache2k by cache2k.
the class CacheLoaderTest method testLoadAll.
@Test
public void testLoadAll() throws ExecutionException, InterruptedException {
AtomicInteger countLoad = new AtomicInteger();
Cache<Integer, Integer> c = target.cache(b -> b.loader(key -> countLoad.incrementAndGet()));
c.get(5);
c.loadAll(asList(5, 6)).get();
assertThat(countLoad.get()).isEqualTo(2);
assertThat(c.get(6)).isEqualTo((Integer) 2);
c.loadAll(asList(5, 6)).get();
c.loadAll(EMPTY_SET);
}
Aggregations