Skip to content

Commit fcdb433

Browse files
authored
Instance tracking leftovers (hazelcast#17416)
Instance tracking leftovers - added jet and jet EE as products to be referenced from jet code - add test for "server" mode
1 parent 6958b22 commit fcdb433

File tree

4 files changed

+111
-3
lines changed

4 files changed

+111
-3
lines changed

hazelcast/src/main/java/com/hazelcast/config/InstanceTrackingConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,15 @@ public enum InstanceProductName {
256256
/**
257257
* Hazelcast java enterprise client
258258
*/
259-
HAZELCAST_CLIENT_EE("Hazelcast Client Enterprise");
259+
HAZELCAST_CLIENT_EE("Hazelcast Client Enterprise"),
260+
/**
261+
* Hazelcast Jet open-source
262+
*/
263+
HAZELCAST_JET("Hazelcast Jet"),
264+
/**
265+
* Hazelcast Jet enterprise
266+
*/
267+
HAZELCAST_JET_EE("Hazelcast Jet Enterprise");
260268

261269
private final String productName;
262270

hazelcast/src/test/java/com/hazelcast/instance/InstanceTrackingInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class InstanceTrackingInfoTest extends HazelcastTestSupport {
5050
public void testJsonFormat() throws IOException {
5151
assertTrackingFileContents(null, content -> {
5252
JsonObject json = Json.parse(content).asObject();
53+
// since we didn't start with HazelcastMemberStarter
54+
// the mode will be "embedded"
5355
assertEquals("embedded", json.getString("mode", ""));
5456
assertEquals("Hazelcast", json.getString("product", ""));
5557
assertEquals(0, json.getInt("licensed", -1));
@@ -97,8 +99,6 @@ public void testCustomFileName() throws IOException {
9799
assertEquals("dummy", bytesToString(Files.readAllBytes(files[0].toPath())));
98100
}
99101

100-
// test hazelcast.tracking.server
101-
102102
private void assertTrackingFileContents(String pattern, Consumer<String> contentAssertion) throws IOException {
103103
Config config = new Config();
104104
File tempFile = tempFolder.newFile();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hazelcast.instance;
18+
19+
import com.hazelcast.core.Hazelcast;
20+
import com.hazelcast.core.server.HazelcastMemberStarter;
21+
import com.hazelcast.internal.json.Json;
22+
import com.hazelcast.internal.json.JsonObject;
23+
import com.hazelcast.test.HazelcastSerialClassRunner;
24+
import com.hazelcast.test.HazelcastTestSupport;
25+
import com.hazelcast.test.OverridePropertyRule;
26+
import com.hazelcast.test.annotation.QuickTest;
27+
import org.junit.After;
28+
import org.junit.Rule;
29+
import org.junit.Test;
30+
import org.junit.experimental.categories.Category;
31+
import org.junit.rules.TemporaryFolder;
32+
import org.junit.runner.RunWith;
33+
34+
import java.io.File;
35+
import java.nio.charset.StandardCharsets;
36+
import java.nio.file.Files;
37+
38+
import static com.hazelcast.test.OverridePropertyRule.set;
39+
import static org.junit.Assert.assertEquals;
40+
41+
/**
42+
* Separate test because it cannot run in parallel with any other instance
43+
* tracking tests.
44+
*/
45+
@RunWith(HazelcastSerialClassRunner.class)
46+
@Category(QuickTest.class)
47+
public class InstanceTrackingServerModeTest extends HazelcastTestSupport {
48+
49+
@Rule
50+
public final TemporaryFolder tempFolder = new TemporaryFolder();
51+
52+
@Rule
53+
public final OverridePropertyRule configOverrideRule
54+
= set("hazelcast.config", "classpath:hazelcast-instance-tracking-test.xml");
55+
56+
@After
57+
public void tearDown() {
58+
System.clearProperty("instance_tracking_filename");
59+
Hazelcast.shutdownAll();
60+
}
61+
62+
@Test
63+
public void testServerMode() throws Exception {
64+
File tempFile = tempFolder.newFile();
65+
System.setProperty("instance_tracking_filename", tempFile.getAbsolutePath());
66+
67+
HazelcastMemberStarter.main(new String[]{});
68+
69+
String actualContents = new String(Files.readAllBytes(tempFile.toPath()), StandardCharsets.UTF_8);
70+
JsonObject json = Json.parse(actualContents).asObject();
71+
assertEquals("server", json.getString("mode", ""));
72+
}
73+
74+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ 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+
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://www.hazelcast.com/schema/config
20+
http://www.hazelcast.com/schema/config/hazelcast-config-4.1.xsd">
21+
22+
<instance-tracking enabled="true">
23+
<file-name>${instance_tracking_filename}</file-name>
24+
</instance-tracking>
25+
26+
</hazelcast>

0 commit comments

Comments
 (0)