Skip to content

Commit 83c9c60

Browse files
authored
IGNITE-24585 Fixed NPE when getting cluster name on inactive cluster (#11892)
1 parent 1ae90a3 commit 83c9c60

6 files changed

Lines changed: 103 additions & 123 deletions

File tree

modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ public void testDeactivateWithCheckClusterNameInConfirmationByDefault() throws E
10521052

10531053
deactivateActiveOrNotClusterWithCheckClusterNameInConfirmation(
10541054
igniteEx,
1055-
igniteEx.context().cache().utilityCache().context().dynamicDeploymentId().toString()
1055+
igniteEx.cluster().id().toString()
10561056
);
10571057
}
10581058

@@ -1164,6 +1164,14 @@ public void testState() throws Exception {
11641164
out = testOut.toString();
11651165

11661166
assertTrue(out.contains("Cluster tag: " + newTag));
1167+
1168+
ignite.cluster().state(INACTIVE);
1169+
1170+
awaitPartitionMapExchange();
1171+
1172+
assertEquals(EXIT_CODE_OK, execute("--state"));
1173+
1174+
assertClusterState(INACTIVE, testOut.toString());
11671175
}
11681176

11691177
/**

modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,12 +1172,8 @@ public final class IgniteSystemProperties {
11721172
" Default is false, which means that service security permissions will be respected")
11731173
public static final String IGNITE_SECURITY_COMPATIBILITY_MODE = "IGNITE_SECURITY_COMPATIBILITY_MODE";
11741174

1175-
/**
1176-
* Ignite cluster name.
1177-
* <p>
1178-
* Defaults to utility cache deployment ID..
1179-
*/
1180-
@SystemProperty(value = "Ignite cluster name. Defaults to utility cache deployment ID", type = String.class)
1175+
/** Ignite cluster name. Defaults to {@link IgniteCluster#id()}. */
1176+
@SystemProperty(value = "Ignite cluster name. Defaults to cluster ID", type = String.class)
11811177
public static final String IGNITE_CLUSTER_NAME = "IGNITE_CLUSTER_NAME";
11821178

11831179
/**

modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/ClusterProcessor.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,16 +852,9 @@ public String latestVersion() {
852852
* @return Cluster name.
853853
* */
854854
public String clusterName() {
855-
try {
856-
ctx.cache().awaitStarted();
857-
}
858-
catch (IgniteCheckedException e) {
859-
throw U.convertException(e);
860-
}
861-
862855
return IgniteSystemProperties.getString(
863856
IGNITE_CLUSTER_NAME,
864-
ctx.cache().utilityCache().context().dynamicDeploymentId().toString()
857+
String.valueOf(ctx.grid().cluster().id())
865858
);
866859
}
867860

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.cluster;
19+
20+
import org.apache.ignite.cluster.ClusterState;
21+
import org.apache.ignite.configuration.DataRegionConfiguration;
22+
import org.apache.ignite.configuration.DataStorageConfiguration;
23+
import org.apache.ignite.configuration.IgniteConfiguration;
24+
import org.apache.ignite.internal.IgniteEx;
25+
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
26+
import org.junit.Test;
27+
import org.junit.runners.Parameterized;
28+
29+
import static org.junit.Assert.assertNotEquals;
30+
31+
/**
32+
* Tests cluster name.
33+
*/
34+
public class IgniteClusterNameTest extends GridCommonAbstractTest {
35+
/** */
36+
@Parameterized.Parameter
37+
public boolean isPersistenceEnabled;
38+
39+
/** */
40+
@Parameterized.Parameters(name = "isPersistenceEnabled={0}")
41+
public static Object[] parameters() {
42+
return new Object[] {false, true};
43+
}
44+
45+
/** {@inheritDoc} */
46+
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
47+
return super.getConfiguration(igniteInstanceName)
48+
.setDataStorageConfiguration(new DataStorageConfiguration()
49+
.setDefaultDataRegionConfiguration(new DataRegionConfiguration()
50+
.setPersistenceEnabled(isPersistenceEnabled)));
51+
}
52+
53+
/** {@inheritDoc} */
54+
@Override protected void afterTest() throws Exception {
55+
super.afterTest();
56+
57+
stopAllGrids();
58+
59+
cleanPersistenceDir();
60+
}
61+
62+
/** @throws Exception If failed. */
63+
@Test
64+
public void testDefaultClusterName() throws Exception {
65+
IgniteEx srv = startGrid(0);
66+
String id = srv.cluster().id().toString();
67+
68+
assertEquals(id, srv.context().cluster().clusterName());
69+
70+
if (isPersistenceEnabled) {
71+
srv.cluster().state(ClusterState.ACTIVE);
72+
73+
assertEquals(id, srv.context().cluster().clusterName());
74+
}
75+
76+
srv.cluster().state(ClusterState.INACTIVE);
77+
78+
assertEquals(id, srv.context().cluster().clusterName());
79+
80+
stopAllGrids();
81+
82+
srv = startGrid(0);
83+
84+
if (isPersistenceEnabled)
85+
assertEquals(id, srv.context().cluster().clusterName());
86+
else
87+
assertNotEquals(id, srv.context().cluster().clusterName());
88+
}
89+
}

modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterNameBeforeActivation.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite13.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Collection;
2222
import java.util.List;
23+
import org.apache.ignite.internal.cluster.IgniteClusterNameTest;
2324
import org.apache.ignite.internal.metric.CacheMetricsAddRemoveTest;
2425
import org.apache.ignite.internal.metric.CacheMetricsConflictResolverTest;
2526
import org.apache.ignite.internal.metric.CustomMetricsTest;
@@ -51,7 +52,6 @@
5152
import org.apache.ignite.internal.processors.cache.transform.CacheObjectTransformationCacheApiTest;
5253
import org.apache.ignite.internal.processors.cache.transform.CacheObjectTransformationEvolutionTest;
5354
import org.apache.ignite.internal.processors.cache.transform.CacheObjectTransformationTest;
54-
import org.apache.ignite.internal.processors.cluster.ClusterNameBeforeActivation;
5555
import org.apache.ignite.internal.processors.continuous.ContinuousQueryBuffersCleanupTest;
5656
import org.apache.ignite.testframework.GridTestUtils;
5757
import org.apache.ignite.testframework.junits.DynamicSuite;
@@ -108,7 +108,7 @@ public static List<Class<?>> suite(Collection<Class> ignoredTests) {
108108
GridTestUtils.addTestIfNeeded(suite, RebalanceStatisticsTest.class, ignoredTests);
109109
GridTestUtils.addTestIfNeeded(suite, TxRecoveryOnCoordniatorFailTest.class, ignoredTests);
110110

111-
GridTestUtils.addTestIfNeeded(suite, ClusterNameBeforeActivation.class, ignoredTests);
111+
GridTestUtils.addTestIfNeeded(suite, IgniteClusterNameTest.class, ignoredTests);
112112

113113
GridTestUtils.addTestIfNeeded(suite, CacheClearAsyncDeadlockTest.class, ignoredTests);
114114

0 commit comments

Comments
 (0)