valepakh commented on code in PR #3522: URL: https://github.com/apache/ignite-3/pull/3522#discussion_r1546273911
########## modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/impl/ConfigurationBasedChannelRegistryTest.java: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.eventlog.impl; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.concurrent.ExecutionException; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; +import org.apache.ignite.internal.eventlog.api.EventChannel; +import org.apache.ignite.internal.eventlog.api.IgniteEventType; +import org.apache.ignite.internal.eventlog.config.schema.EventLogConfiguration; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(ConfigurationExtension.class) +class ConfigurationBasedChannelRegistryTest extends BaseIgniteAbstractTest { + private static final String TEST_CHANNEL = "testChannel"; + + @InjectConfiguration + private EventLogConfiguration cfg; + + private ConfigurationBasedChannelRegistry registry; + + @BeforeEach + void setUp() { + registry = new ConfigurationBasedChannelRegistry(cfg, new ConfigurationBasedSinkRegistry(cfg)); + } + + @Test + void noSuchChannel() { + assertNull(registry.getByName("noSuchChannel")); + } + + @Test + void addNewConfigurationEntry() throws Exception { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // When get channel from registry. + EventChannel channel = registry.getByName(TEST_CHANNEL); + + // Then it is configured correctly. + assertThat(channel.types(), hasItem(IgniteEventType.USER_AUTHENTICATED.name())); + } + + @Test + void removeConfigurationEntry() throws Exception { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // When remove configuration entry. + cfg.change(c -> c.changeChannels().delete(TEST_CHANNEL)).get(); + + // Then channel is removed from registry. + assertThat(registry.getByName(TEST_CHANNEL), nullValue()); + } + + @Test + void updateConfigurationEntry() throws ExecutionException, InterruptedException { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + assertThat(registry.getByName(TEST_CHANNEL).types(), hasSize(1)); + + // When update configuration entry. + cfg.channels().change(c -> c.update(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name(), IgniteEventType.CONNECTION_CLOSED.name()); + })).get(); + + // Then channel is updated in registry and types are not the same as the were before the update. + assertThat(registry.getByName(TEST_CHANNEL).types(), hasSize(2)); + } + + @Test + void findAllChannelsByEventType() throws ExecutionException, InterruptedException { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // Then registry returns the channel by type. + assertThat(registry.findAllChannelsByEventType(IgniteEventType.USER_AUTHENTICATED.name()).size(), is(1)); + // But for another type it returns empty set. + assertThat(registry.findAllChannelsByEventType(IgniteEventType.CONNECTION_CLOSED.name()).size(), is(0)); Review Comment: is(empty())? ########## modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/impl/ConfigurationBasedChannelRegistryTest.java: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.eventlog.impl; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.concurrent.ExecutionException; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; +import org.apache.ignite.internal.eventlog.api.EventChannel; +import org.apache.ignite.internal.eventlog.api.IgniteEventType; +import org.apache.ignite.internal.eventlog.config.schema.EventLogConfiguration; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(ConfigurationExtension.class) +class ConfigurationBasedChannelRegistryTest extends BaseIgniteAbstractTest { + private static final String TEST_CHANNEL = "testChannel"; + + @InjectConfiguration + private EventLogConfiguration cfg; + + private ConfigurationBasedChannelRegistry registry; + + @BeforeEach + void setUp() { + registry = new ConfigurationBasedChannelRegistry(cfg, new ConfigurationBasedSinkRegistry(cfg)); + } + + @Test + void noSuchChannel() { + assertNull(registry.getByName("noSuchChannel")); + } + + @Test + void addNewConfigurationEntry() throws Exception { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // When get channel from registry. + EventChannel channel = registry.getByName(TEST_CHANNEL); + + // Then it is configured correctly. + assertThat(channel.types(), hasItem(IgniteEventType.USER_AUTHENTICATED.name())); + } + + @Test + void removeConfigurationEntry() throws Exception { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // When remove configuration entry. + cfg.change(c -> c.changeChannels().delete(TEST_CHANNEL)).get(); + + // Then channel is removed from registry. + assertThat(registry.getByName(TEST_CHANNEL), nullValue()); + } + + @Test + void updateConfigurationEntry() throws ExecutionException, InterruptedException { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + assertThat(registry.getByName(TEST_CHANNEL).types(), hasSize(1)); + + // When update configuration entry. + cfg.channels().change(c -> c.update(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name(), IgniteEventType.CONNECTION_CLOSED.name()); + })).get(); + + // Then channel is updated in registry and types are not the same as the were before the update. + assertThat(registry.getByName(TEST_CHANNEL).types(), hasSize(2)); + } + + @Test + void findAllChannelsByEventType() throws ExecutionException, InterruptedException { + // Given configuration with a channel. + cfg.channels().change(c -> c.create(TEST_CHANNEL, s -> { + s.changeEnabled(true); + s.changeEvents(IgniteEventType.USER_AUTHENTICATED.name()); + })).get(); + + // Then registry returns the channel by type. + assertThat(registry.findAllChannelsByEventType(IgniteEventType.USER_AUTHENTICATED.name()).size(), is(1)); Review Comment: hasSize? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
