use of java.util.Collections in project ovirt-engine by oVirt.
the class HostedEngineConfigFetcher method loadConfigMap.
/**
* Take a array of data, parse it to a Map of key: String -> val: String
* @param data byte[] loaded by the previously fetched file
* @return A key value map of the hosted engine configuration 'as is' represented by the data passed or
* {@linkplain Collections#emptyMap} in case some error occurred.
*/
protected Map<String, String> loadConfigMap(final byte[] data) {
try (ByteArrayInputStream input = new ByteArrayInputStream(data)) {
Properties properties = new Properties();
properties.load(input);
return properties.entrySet().stream().collect(Collectors.toMap(e -> (String) e.getKey(), e -> (String) e.getValue()));
} catch (IOException e) {
log.error("Failed to load hosted-engine.conf map from file due to {}", e);
return Collections.emptyMap();
}
}
use of java.util.Collections in project jnosql-diana by eclipse.
the class SetTypeReferenceReader method convert.
@Override
public <T> T convert(TypeSupplier<T> typeReference, Object value) {
Type type = typeReference.get();
ParameterizedType parameterizedType = ParameterizedType.class.cast(type);
Class<?> classType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
if (Iterable.class.isInstance(value)) {
Iterable iterable = Iterable.class.cast(value);
return (T) stream(iterable.spliterator(), false).map(o -> SERVICE_PROVIDER.read(classType, o)).collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
}
return (T) singleton(SERVICE_PROVIDER.read(classType, value));
}
use of java.util.Collections in project jnosql-diana by eclipse.
the class ListTypeReferenceReader method convert.
@Override
public <T> T convert(TypeSupplier<T> typeReference, Object value) {
Type type = typeReference.get();
ParameterizedType parameterizedType = ParameterizedType.class.cast(type);
Class<?> classType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
if (Iterable.class.isInstance(value)) {
Iterable iterable = Iterable.class.cast(value);
return (T) stream(iterable.spliterator(), false).map(o -> SERVICE_PROVIDER.read(classType, o)).collect(collectingAndThen(toList(), Collections::unmodifiableList));
}
return (T) singletonList(SERVICE_PROVIDER.read(classType, value));
}
use of java.util.Collections in project cassandra by apache.
the class JVMDTestTest method nonSharedConfigClassTest.
@Test
public void nonSharedConfigClassTest() throws IOException {
Map<String, Object> commitLogCompression = ImmutableMap.of("class_name", "org.apache.cassandra.io.compress.LZ4Compressor", "parameters", Collections.<String, Object>emptyMap());
Map<String, Object> encryptionOptions = ImmutableMap.of("cipher_suites", Collections.singletonList("FakeCipher"), "optional", false, "enabled", false);
try (Cluster cluster = Cluster.build(1).withConfig(c -> {
c.set("concurrent_reads", 321);
c.set("internode_compression", Config.InternodeCompression.dc);
c.set("client_encryption_options", encryptionOptions);
c.set("commitlog_compression", commitLogCompression);
}).start()) {
cluster.get(1).runOnInstance(() -> {
assertEquals(321, Stage.READ.getMaximumPoolSize());
assertEquals(Config.InternodeCompression.dc, DatabaseDescriptor.internodeCompression());
assertEquals(Collections.singletonList("FakeCipher"), DatabaseDescriptor.getNativeProtocolEncryptionOptions().cipher_suites);
assertEquals("org.apache.cassandra.io.compress.LZ4Compressor", DatabaseDescriptor.getCommitLogCompression().class_name);
assertTrue(DatabaseDescriptor.getCommitLogCompression().parameters.isEmpty());
});
}
}
use of java.util.Collections in project kafka by apache.
the class KStreamImplTest method shouldPreserveSerdesForOperators.
// specifically testing the deprecated variant
@SuppressWarnings({ "rawtypes", "deprecation" })
@Test
public void shouldPreserveSerdesForOperators() {
final StreamsBuilder builder = new StreamsBuilder();
final KStream<String, String> stream1 = builder.stream(Collections.singleton("topic-1"), stringConsumed);
final KTable<String, String> table1 = builder.table("topic-2", stringConsumed);
final GlobalKTable<String, String> table2 = builder.globalTable("topic-2", stringConsumed);
final ConsumedInternal<String, String> consumedInternal = new ConsumedInternal<>(stringConsumed);
final KeyValueMapper<String, String, String> selector = (key, value) -> key;
final KeyValueMapper<String, String, Iterable<KeyValue<String, String>>> flatSelector = (key, value) -> Collections.singleton(new KeyValue<>(key, value));
final ValueMapper<String, String> mapper = value -> value;
final ValueMapper<String, Iterable<String>> flatMapper = Collections::singleton;
final ValueJoiner<String, String, String> joiner = (value1, value2) -> value1;
assertEquals(((AbstractStream) stream1.filter((key, value) -> false)).keySerde(), consumedInternal.keySerde());
assertEquals(((AbstractStream) stream1.filter((key, value) -> false)).valueSerde(), consumedInternal.valueSerde());
assertEquals(((AbstractStream) stream1.filterNot((key, value) -> false)).keySerde(), consumedInternal.keySerde());
assertEquals(((AbstractStream) stream1.filterNot((key, value) -> false)).valueSerde(), consumedInternal.valueSerde());
assertNull(((AbstractStream) stream1.selectKey(selector)).keySerde());
assertEquals(((AbstractStream) stream1.selectKey(selector)).valueSerde(), consumedInternal.valueSerde());
assertNull(((AbstractStream) stream1.map(KeyValue::new)).keySerde());
assertNull(((AbstractStream) stream1.map(KeyValue::new)).valueSerde());
assertEquals(((AbstractStream) stream1.mapValues(mapper)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.mapValues(mapper)).valueSerde());
assertNull(((AbstractStream) stream1.flatMap(flatSelector)).keySerde());
assertNull(((AbstractStream) stream1.flatMap(flatSelector)).valueSerde());
assertEquals(((AbstractStream) stream1.flatMapValues(flatMapper)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.flatMapValues(flatMapper)).valueSerde());
assertNull(((AbstractStream) stream1.transform(transformerSupplier)).keySerde());
assertNull(((AbstractStream) stream1.transform(transformerSupplier)).valueSerde());
assertEquals(((AbstractStream) stream1.transformValues(valueTransformerSupplier)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.transformValues(valueTransformerSupplier)).valueSerde());
assertNull(((AbstractStream) stream1.merge(stream1)).keySerde());
assertNull(((AbstractStream) stream1.merge(stream1)).valueSerde());
assertEquals(((AbstractStream) stream1.through("topic-3")).keySerde(), consumedInternal.keySerde());
assertEquals(((AbstractStream) stream1.through("topic-3")).valueSerde(), consumedInternal.valueSerde());
assertEquals(((AbstractStream) stream1.through("topic-3", Produced.with(mySerde, mySerde))).keySerde(), mySerde);
assertEquals(((AbstractStream) stream1.through("topic-3", Produced.with(mySerde, mySerde))).valueSerde(), mySerde);
assertEquals(((AbstractStream) stream1.repartition()).keySerde(), consumedInternal.keySerde());
assertEquals(((AbstractStream) stream1.repartition()).valueSerde(), consumedInternal.valueSerde());
assertEquals(((AbstractStream) stream1.repartition(Repartitioned.with(mySerde, mySerde))).keySerde(), mySerde);
assertEquals(((AbstractStream) stream1.repartition(Repartitioned.with(mySerde, mySerde))).valueSerde(), mySerde);
assertEquals(((AbstractStream) stream1.groupByKey()).keySerde(), consumedInternal.keySerde());
assertEquals(((AbstractStream) stream1.groupByKey()).valueSerde(), consumedInternal.valueSerde());
assertEquals(((AbstractStream) stream1.groupByKey(Grouped.with(mySerde, mySerde))).keySerde(), mySerde);
assertEquals(((AbstractStream) stream1.groupByKey(Grouped.with(mySerde, mySerde))).valueSerde(), mySerde);
assertNull(((AbstractStream) stream1.groupBy(selector)).keySerde());
assertEquals(((AbstractStream) stream1.groupBy(selector)).valueSerde(), consumedInternal.valueSerde());
assertEquals(((AbstractStream) stream1.groupBy(selector, Grouped.with(mySerde, mySerde))).keySerde(), mySerde);
assertEquals(((AbstractStream) stream1.groupBy(selector, Grouped.with(mySerde, mySerde))).valueSerde(), mySerde);
assertNull(((AbstractStream) stream1.join(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).keySerde());
assertNull(((AbstractStream) stream1.join(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).valueSerde());
assertEquals(((AbstractStream) stream1.join(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).keySerde(), mySerde);
assertNull(((AbstractStream) stream1.join(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).valueSerde());
assertNull(((AbstractStream) stream1.leftJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).keySerde());
assertNull(((AbstractStream) stream1.leftJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).valueSerde());
assertEquals(((AbstractStream) stream1.leftJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).keySerde(), mySerde);
assertNull(((AbstractStream) stream1.leftJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).valueSerde());
assertNull(((AbstractStream) stream1.outerJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).keySerde());
assertNull(((AbstractStream) stream1.outerJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)))).valueSerde());
assertEquals(((AbstractStream) stream1.outerJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).keySerde(), mySerde);
assertNull(((AbstractStream) stream1.outerJoin(stream1, joiner, JoinWindows.of(Duration.ofMillis(100L)), StreamJoined.with(mySerde, mySerde, mySerde))).valueSerde());
assertEquals(((AbstractStream) stream1.join(table1, joiner)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.join(table1, joiner)).valueSerde());
assertEquals(((AbstractStream) stream1.join(table1, joiner, Joined.with(mySerde, mySerde, mySerde))).keySerde(), mySerde);
assertNull(((AbstractStream) stream1.join(table1, joiner, Joined.with(mySerde, mySerde, mySerde))).valueSerde());
assertEquals(((AbstractStream) stream1.leftJoin(table1, joiner)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.leftJoin(table1, joiner)).valueSerde());
assertEquals(((AbstractStream) stream1.leftJoin(table1, joiner, Joined.with(mySerde, mySerde, mySerde))).keySerde(), mySerde);
assertNull(((AbstractStream) stream1.leftJoin(table1, joiner, Joined.with(mySerde, mySerde, mySerde))).valueSerde());
assertEquals(((AbstractStream) stream1.join(table2, selector, joiner)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.join(table2, selector, joiner)).valueSerde());
assertEquals(((AbstractStream) stream1.leftJoin(table2, selector, joiner)).keySerde(), consumedInternal.keySerde());
assertNull(((AbstractStream) stream1.leftJoin(table2, selector, joiner)).valueSerde());
}
Aggregations