forked from apache/geode
/
ClusterConfigServerRestartWithJarDeployDUnitTest.java
134 lines (107 loc) · 5.13 KB
/
ClusterConfigServerRestartWithJarDeployDUnitTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* 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.geode.management.internal.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.FunctionInvocationTargetException;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.test.compiler.JarBuilder;
import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
import org.apache.geode.util.test.TestUtil;
public class ClusterConfigServerRestartWithJarDeployDUnitTest {
@Rule
public ClusterStartupRule rule = new ClusterStartupRule(5);
@Rule
public GfshCommandRule gfsh = new GfshCommandRule();
@Rule
public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
@Test
public void functionExecutionAfterServerReconnect() throws Exception {
IgnoredException.addIgnoredException("org.apache.geode.ForcedDisconnectException: for testing");
IgnoredException.addIgnoredException("cluster configuration service not available");
IgnoredException.addIgnoredException("This thread has been stalled");
IgnoredException
.addIgnoredException("member unexpectedly shut down shared, unordered connection");
IgnoredException.addIgnoredException("Connection refused");
MemberVM locator0 = rule.startLocatorVM(0);
gfsh.connectAndVerify(locator0);
gfsh.executeAndAssertThat(
"configure pdx --read-serialized=true --auto-serializable-classes=ClusterConfigServerRestartWithJarDeployFunction.*");
Properties props = new Properties();
MemberVM server1 = rule.startServerVM(1, props, locator0.getPort());
MemberVM server2 = rule.startServerVM(2, props, locator0.getPort());
File functionJar = getFunctionJar();
gfsh.executeAndAssertThat("deploy --jar=" + functionJar.getAbsolutePath()).statusIsSuccess();
callFunction(server1);
server2.forceDisconnect();
server2.waitTilFullyReconnected();
callFunction(server1);
}
private File getFunctionJar() throws IOException {
JarBuilder jarBuilder = new JarBuilder();
String filePath =
TestUtil.getResourcePath(this.getClass(),
"/ClusterConfigServerRestartWithJarDeployFunction.java");
assertThat(filePath).as("java file resource not found").isNotBlank();
File functionJar = new File(temporaryFolder.newFolder(), "output.jar");
jarBuilder.buildJar(functionJar, new File(filePath));
return functionJar;
}
private void callFunction(MemberVM member) {
member.invoke(() -> {
while (true) {
try {
Set<InternalDistributedMember> others =
ClusterStartupRule.getCache().getDistributionManager()
.getOtherNormalDistributionManagerIds();
InternalDistributedMember otherMember = others.stream().findFirst().get();
Class<?> studentClass = ClassPathLoader.getLatest()
.forName("ClusterConfigServerRestartWithJarDeployFunction$Student");
Object student = studentClass.getConstructor().newInstance();
ResultCollector collector = FunctionService.onMember(otherMember)
.setArguments(student)
.execute("student-function");
List<Object> results = (List<Object>) collector.getResult();
break;
} catch (FunctionException fex) {
if (fex.getCause() instanceof FunctionInvocationTargetException) {
LogService.getLogger().info("Sleeping for 500ms after recoverable exception {}",
fex.getMessage());
Thread.sleep(500);
} else {
fail("Exception received from function execution: %s", fex.getMessage());
throw fex;
}
}
}
});
}
}