You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2020/02/14 12:21:11 UTC
[ignite] branch master updated: IGNITE-12668 Extends test coverage
for plugin providers configuration
This is an automated email from the ASF dual-hosted git repository.
agura pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 995d259 IGNITE-12668 Extends test coverage for plugin providers configuration
995d259 is described below
commit 995d259767eb5a60807cfafdf6044445fb794a31
Author: Andrey Gura <ag...@apache.org>
AuthorDate: Mon Feb 10 18:14:14 2020 +0300
IGNITE-12668 Extends test coverage for plugin providers configuration
---
.../ignite/plugin/PluginConfigurationTest.java | 196 +++++++++++++++++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 2 +
2 files changed, 198 insertions(+)
diff --git a/modules/core/src/test/java/org/apache/ignite/plugin/PluginConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/plugin/PluginConfigurationTest.java
new file mode 100644
index 0000000..7f46a74
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/plugin/PluginConfigurationTest.java
@@ -0,0 +1,196 @@
+/*
+ * 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.plugin;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+/**
+ * Tests for Ignite plugin configuration.
+ */
+public class PluginConfigurationTest extends GridCommonAbstractTest {
+ /** Test plugin name. */
+ private static final String TEST_PLUGIN_NAME = "test_plugin";
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * Tests that {@link ServiceLoader#load(Class)} result will be used if plugin providers is not configured
+ * explicitly.
+ */
+ @Test
+ public void testNullPluginProviders() throws Exception {
+ doTest(null, U.allPluginProviders());
+ }
+
+ /**
+ * Tests that {@link ServiceLoader#load(Class)} result will be used if plugin providers is empty for
+ * {@link IgniteConfiguration}.
+ */
+ @Test
+ @SuppressWarnings("ZeroLengthArrayAllocation")
+ public void testEmptyPluginProviders() throws Exception {
+ doTest(new PluginProvider[]{}, U.allPluginProviders());
+ }
+
+ /**
+ * Tests that explicitly configured plugin providers will be used.
+ */
+ @Test
+ public void testNotEmptyPluginProviders() throws Exception {
+ TestPluginProvider testPluginProvider = new TestPluginProvider();
+
+ doTest(new PluginProvider[]{testPluginProvider}, Collections.singletonList(testPluginProvider));
+ }
+
+ /**
+ * Asserts expectations.
+ *
+ * @param cfgProviders Config providers.
+ * @param expProviders Expected providers.
+ */
+ @SuppressWarnings("rawtypes")
+ private void doTest(PluginProvider<?>[] cfgProviders, List<PluginProvider> expProviders) throws Exception {
+ List<String> exp = toClasses(expProviders);
+
+ IgniteConfiguration cfg = getConfiguration();
+
+ cfg.setPluginProviders(cfgProviders);
+
+ IgniteEx ignite = startGrid(cfg);
+
+ List<String> providers = toClasses(ignite.context().plugins().allProviders());
+
+ assertEqualsCollections(exp, providers);
+ }
+
+ /**
+ * @param col Collection of plugin providers
+ */
+ @SuppressWarnings("rawtypes")
+ private static List<String> toClasses(Collection<PluginProvider> col) {
+ return col.stream().map(PluginProvider::name).collect(Collectors.toList());
+ }
+
+ /** Plugin with own message factory. */
+ private static class TestPlugin implements IgnitePlugin {
+ }
+
+ /** */
+ @SuppressWarnings("RedundantThrows")
+ public static class TestPluginProvider implements PluginProvider<TestPluginConfiguration> {
+ /** {@inheritDoc} */
+ @Override public String name() {
+ return TEST_PLUGIN_NAME;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends IgnitePlugin> T plugin() {
+ return (T)new TestPlugin();
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> @Nullable T createComponent(PluginContext ctx, Class<T> cls) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String version() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String copyright() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("rawtypes")
+ @Override public CachePluginProvider createCacheProvider(CachePluginContext ctx) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void start(PluginContext ctx) throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void stop(boolean cancel) throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onIgniteStart() throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onIgniteStop(boolean cancel) {
+ // no-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public @Nullable Serializable provideDiscoveryData(UUID nodeId) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void receiveDiscoveryData(UUID nodeId, Serializable data) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void validateNewNode(ClusterNode node) throws PluginValidationException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void validateNewNode(ClusterNode node, Serializable data) {
+ // No-op.
+ }
+ }
+
+ /** */
+ private static class TestPluginConfiguration implements PluginConfiguration {
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 35c00cd..44a01a6 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -111,6 +111,7 @@ import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest;
import org.apache.ignite.messaging.GridMessagingSelfTest;
import org.apache.ignite.messaging.IgniteMessagingSendAsyncTest;
import org.apache.ignite.messaging.IgniteMessagingWithClientTest;
+import org.apache.ignite.plugin.PluginConfigurationTest;
import org.apache.ignite.plugin.PluginNodeValidationTest;
import org.apache.ignite.plugin.security.SecurityPermissionSetBuilderTest;
import org.apache.ignite.spi.GridSpiLocalHostInjectionTest;
@@ -256,6 +257,7 @@ import org.junit.runners.Suite;
CacheLocalGetSerializationTest.class,
PluginNodeValidationTest.class,
+ PluginConfigurationTest.class,
// In-memory Distributed MetaStorage.
DistributedMetaStorageTest.class,