You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by nt...@apache.org on 2016/04/04 20:38:41 UTC
[35/37] ignite git commit: IGNITE-2668: MBean creation fails if cache
name contains ':' character
IGNITE-2668: MBean creation fails if cache name contains ':' character
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c901425c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c901425c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c901425c
Branch: refs/heads/ignite-2004
Commit: c901425c64b0f18c3d5fdbef8956b7ab68d61ad9
Parents: b09ecd7
Author: Vladislav Pyatkov <vl...@gmail.com>
Authored: Mon Apr 4 18:05:19 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Mon Apr 4 18:05:19 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/util/IgniteUtils.java | 8 ++-
.../CacheNamesWithSpecialCharactersTest.java | 71 ++++++++++++++++++++
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
3 files changed, 80 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c901425c/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 7b2414f..29c1083 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -293,6 +293,9 @@ public abstract class IgniteUtils {
/** Secure socket protocol to use. */
private static final String HTTPS_PROTOCOL = "TLS";
+ /** Correct Mbean cache name pattern. */
+ private static Pattern MBEAN_CACHE_NAME_PATTERN = Pattern.compile("^[a-zA-Z_0-9]+$");
+
/** Project home directory. */
private static volatile GridTuple<String> ggHome;
@@ -4323,7 +4326,10 @@ public abstract class IgniteUtils {
cacheName = maskName(cacheName);
- sb.a("group=").a(cacheName).a(',');
+ if (!MBEAN_CACHE_NAME_PATTERN.matcher(cacheName).matches())
+ sb.a("group=").a('\"').a(cacheName).a('\"').a(',');
+ else
+ sb.a("group=").a(cacheName).a(',');
sb.a("name=").a(name);
http://git-wip-us.apache.org/repos/asf/ignite/blob/c901425c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNamesWithSpecialCharactersTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNamesWithSpecialCharactersTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNamesWithSpecialCharactersTest.java
new file mode 100644
index 0000000..04cfce7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNamesWithSpecialCharactersTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.processors.cache;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collection;
+
+/**
+ * Test that validates {@link Ignite#cacheNames()} implementation.
+ */
+public class CacheNamesWithSpecialCharactersTest extends GridCommonAbstractTest {
+
+ public static final String CACHE_NAME_1 = "--№=+:(replicated)";
+ public static final String CACHE_NAME_2 = ":_&:: (partitioned)";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg1 = new CacheConfiguration();
+ cacheCfg1.setCacheMode(CacheMode.REPLICATED);
+ cacheCfg1.setName(CACHE_NAME_1);
+
+ CacheConfiguration cacheCfg2 = new CacheConfiguration();
+ cacheCfg2.setCacheMode(CacheMode.PARTITIONED);
+ cacheCfg2.setName(CACHE_NAME_2);
+
+ cfg.setCacheConfiguration(cacheCfg1, cacheCfg2);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception In case of failure.
+ */
+ public void testCacheNames() throws Exception {
+ try {
+ startGridsMultiThreaded(2);
+
+ Collection<String> names = grid(0).cacheNames();
+
+ assertEquals(2, names.size());
+
+ for (String name : names)
+ assertTrue(name.equals(CACHE_NAME_1) || name.equals(CACHE_NAME_2));
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c901425c/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 9892ff7..75674fa 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -40,6 +40,7 @@ import org.apache.ignite.internal.processors.cache.CacheDeferredDeleteSanitySelf
import org.apache.ignite.internal.processors.cache.CacheEntryProcessorCopySelfTest;
import org.apache.ignite.internal.processors.cache.CacheFutureExceptionSelfTest;
import org.apache.ignite.internal.processors.cache.CacheNamesSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheNamesWithSpecialCharactersTest;
import org.apache.ignite.internal.processors.cache.CachePutEventListenerErrorSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheAffinityApiSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheAffinityMapperSelfTest;
@@ -216,6 +217,7 @@ public class IgniteCacheTestSuite extends TestSuite {
// Common tests.
suite.addTestSuite(CacheNamesSelfTest.class);
+ suite.addTestSuite(CacheNamesWithSpecialCharactersTest.class);
suite.addTestSuite(GridCacheConcurrentMapSelfTest.class);
suite.addTestSuite(GridCacheAffinityMapperSelfTest.class);
suite.addTestSuite(CacheAffinityCallSelfTest.class);