Search in sources :

Example 91 with Collections

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();
    }
}
Also used : ResourceManager(org.ovirt.engine.core.vdsbroker.ResourceManager) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ByteBuffer(java.nio.ByteBuffer) Inject(javax.inject.Inject) ActionType(org.ovirt.engine.core.common.action.ActionType) ByteArrayInputStream(java.io.ByteArrayInputStream) BackendInternal(org.ovirt.engine.core.bll.interfaces.BackendInternal) Map(java.util.Map) Instance(javax.enterprise.inject.Instance) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Properties(java.util.Properties) Logger(org.slf4j.Logger) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) IOException(java.io.IOException) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) StoragePoolDomainAndGroupIdBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters) Collectors(java.util.stream.Collectors) EngineError(org.ovirt.engine.core.common.errors.EngineError) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) Optional(java.util.Optional) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) RetrieveImageDataParameters(org.ovirt.engine.core.bll.RetrieveImageDataParameters) GetImagesListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters) Collections(java.util.Collections) TarInMemoryExport(org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Example 92 with Collections

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));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Collections(java.util.Collections)

Example 93 with Collections

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));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Collections(java.util.Collections)

Example 94 with Collections

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());
        });
    }
}
Also used : Feature(org.apache.cassandra.distributed.api.Feature) Stage(org.apache.cassandra.concurrent.Stage) FBUtilities(org.apache.cassandra.utils.FBUtilities) LogAction(org.apache.cassandra.distributed.api.LogAction) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Config(org.apache.cassandra.config.Config) TimeoutException(java.util.concurrent.TimeoutException) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) TimeUnit(java.util.concurrent.TimeUnit) AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Cluster(org.apache.cassandra.distributed.Cluster) Collections(java.util.Collections) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) Assert.assertEquals(org.junit.Assert.assertEquals) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 95 with Collections

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());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) ValueTransformerSupplier(org.apache.kafka.streams.kstream.ValueTransformerSupplier) Produced(org.apache.kafka.streams.kstream.Produced) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Stores(org.apache.kafka.streams.state.Stores) Repartitioned(org.apache.kafka.streams.kstream.Repartitioned) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Joined(org.apache.kafka.streams.kstream.Joined) MockApiProcessor(org.apache.kafka.test.MockApiProcessor) Matcher(java.util.regex.Matcher) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) ProcessorSupplier(org.apache.kafka.streams.processor.api.ProcessorSupplier) MockApiProcessorSupplier(org.apache.kafka.test.MockApiProcessorSupplier) TransformerSupplier(org.apache.kafka.streams.kstream.TransformerSupplier) Serde(org.apache.kafka.common.serialization.Serde) Arrays.asList(java.util.Arrays.asList) TopologyWrapper(org.apache.kafka.streams.TopologyWrapper) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) Duration(java.time.Duration) Map(java.util.Map) SourceNode(org.apache.kafka.streams.processor.internals.SourceNode) Serdes(org.apache.kafka.common.serialization.Serdes) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) TestRecord(org.apache.kafka.streams.test.TestRecord) ValueMapperWithKey(org.apache.kafka.streams.kstream.ValueMapperWithKey) MockValueJoiner(org.apache.kafka.test.MockValueJoiner) MockMapper(org.apache.kafka.test.MockMapper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TopicNameExtractor(org.apache.kafka.streams.processor.TopicNameExtractor) KeyValue(org.apache.kafka.streams.KeyValue) Instant(java.time.Instant) Bytes(org.apache.kafka.common.utils.Bytes) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) List(java.util.List) Predicate(org.apache.kafka.streams.kstream.Predicate) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) ValueJoiner(org.apache.kafka.streams.kstream.ValueJoiner) Materialized(org.apache.kafka.streams.kstream.Materialized) Pattern(java.util.regex.Pattern) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Duration.ofMillis(java.time.Duration.ofMillis) Topology(org.apache.kafka.streams.Topology) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) KStream(org.apache.kafka.streams.kstream.KStream) Function(java.util.function.Function) StreamJoined(org.apache.kafka.streams.kstream.StreamJoined) ArrayList(java.util.ArrayList) ValueJoinerWithKey(org.apache.kafka.streams.kstream.ValueJoinerWithKey) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Named(org.apache.kafka.streams.kstream.Named) ValueTransformer(org.apache.kafka.streams.kstream.ValueTransformer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) ValueMapper(org.apache.kafka.streams.kstream.ValueMapper) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) Collections.emptyMap(java.util.Collections.emptyMap) KTable(org.apache.kafka.streams.kstream.KTable) KeyValueMapper(org.apache.kafka.streams.kstream.KeyValueMapper) TestOutputTopic(org.apache.kafka.streams.TestOutputTopic) Properties(java.util.Properties) Consumed(org.apache.kafka.streams.kstream.Consumed) Transformer(org.apache.kafka.streams.kstream.Transformer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValueTransformerWithKeySupplier(org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier) KeyValueTimestamp(org.apache.kafka.streams.KeyValueTimestamp) Grouped(org.apache.kafka.streams.kstream.Grouped) TimeUnit(java.util.concurrent.TimeUnit) FailOnInvalidTimestamp(org.apache.kafka.streams.processor.FailOnInvalidTimestamp) Assert.assertNull(org.junit.Assert.assertNull) GlobalKTable(org.apache.kafka.streams.kstream.GlobalKTable) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) ValueTransformerWithKey(org.apache.kafka.streams.kstream.ValueTransformerWithKey) TestInputTopic(org.apache.kafka.streams.TestInputTopic) StreamsTestUtils(org.apache.kafka.test.StreamsTestUtils) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) KeyValue(org.apache.kafka.streams.KeyValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)113 List (java.util.List)59 ArrayList (java.util.ArrayList)41 Test (org.junit.Test)39 Map (java.util.Map)37 Collectors (java.util.stream.Collectors)34 Arrays (java.util.Arrays)28 HashMap (java.util.HashMap)26 Set (java.util.Set)25 HashSet (java.util.HashSet)23 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Optional (java.util.Optional)19 TimeUnit (java.util.concurrent.TimeUnit)16 URI (java.net.URI)13 Assert (org.junit.Assert)13 Function (java.util.function.Function)12 Stream (java.util.stream.Stream)12 Before (org.junit.Before)12 Logger (org.slf4j.Logger)12