This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
BackoffSuite.java
291 lines (220 loc) · 10 KB
/
BackoffSuite.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* Copyright 1999-2011 University of Chicago
*
* Licensed 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.globus.workspace.testing.suites.failure;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import org.globus.workspace.testing.NimbusTestBase;
import org.globus.workspace.testing.NimbusTestContextLoader;
import org.globus.workspace.xen.xenssh.MockShutdownTrash;
import org.nimbustools.api.repr.Caller;
import org.nimbustools.api.repr.CreateResult;
import org.nimbustools.api.repr.vm.VM;
import org.nimbustools.api.services.rm.Manager;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
@ContextConfiguration(
locations={"file:./service/service/java/tests/suites/failure/home/services/etc/nimbus/workspace-service/other/main.xml"},
loader=NimbusTestContextLoader.class)
public class BackoffSuite extends NimbusTestBase {
// -----------------------------------------------------------------------------------------
// extends NimbusTestBase
// -----------------------------------------------------------------------------------------
@AfterSuite(alwaysRun=true)
@Override
public void suiteTeardown() throws Exception {
super.suiteTeardown();
}
/**
* This is how coordinate your Java test suite code with the conf files to use.
* @return absolute path to the value that should be set for $NIMBUS_HOME
* @throws Exception if $NIMBUS_HOME cannot be determined
*/
@Override
protected String getNimbusHome() throws Exception {
return this.determineSuitesPath() + "/failure/home";
}
// -----------------------------------------------------------------------------------------
// PREREQ TESTS (if any of these fail, nothing else will work at all)
// -----------------------------------------------------------------------------------------
/**
* Check if ModuleLocator can be retrieved and used at all.
*/
@Test(groups="pr3r3qs")
public void retrieveModuleLocator() throws Exception {
logger.debug("retrieveModuleLocator");
final Manager rm = this.locator.getManager();
final VM[] vms = rm.getGlobalAll();
// we know there are zero so far because it is in group 'prereqs'
assertEquals(0, vms.length);
}
// -----------------------------------------------------------------------------------------
// FAILURE BEHAVIOR
// -----------------------------------------------------------------------------------------
@Test(groups="nobackoff", dependsOnGroups="pr3r3qs")
public void noBackoff() throws Exception {
logger.debug("nobackoff");
final Manager rm = this.locator.getManager();
VM[] allvms = rm.getGlobalAll();
assertEquals(0, allvms.length);
MockShutdownTrash.resetFailCount();
final Caller caller = this.populator().getCaller();
final CreateResult result =
rm.create(this.populator().getCreateRequest("suite:backoff:nobackoff"),
caller);
final VM[] vms = result.getVMs();
assertEquals(1, vms.length);
assertNotNull(vms[0]);
logger.info("Leased vm '" + vms[0].getID() + '\'');
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
Thread.sleep(2000L);
assertEquals(0, MockShutdownTrash.getFailCount());
// Fail at killing the instance:
MockShutdownTrash.setFail(true);
logger.warn("Set to fail.");
rm.trash(vms[0].getID(), Manager.INSTANCE, caller);
Thread.sleep(2000L);
// Check that it is at least trying to terminate the node:
int lastFailCount = MockShutdownTrash.getFailCount();
assertFalse(0 == lastFailCount);
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
allvms = rm.getGlobalAll();
assertEquals(1, allvms.length);
long lastFailMs = MockShutdownTrash.getMsAtLastAttempt();
assertFalse(0 == lastFailMs);
Thread.sleep(4000L);
long nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
assertFalse(nextFailMs == lastFailMs);
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
allvms = rm.getGlobalAll();
assertEquals(1, allvms.length);
// Start succeeding to kill the instance:
MockShutdownTrash.setFail(false);
logger.warn("Set to succeed.");
Thread.sleep(4000L);
// Should now be gone:
assertFalse(rm.exists(vms[0].getID(), Manager.INSTANCE));
allvms = rm.getGlobalAll();
assertEquals(0, allvms.length);
long finalFailMs = MockShutdownTrash.getMsAtLastAttempt();
assertFalse(finalFailMs == nextFailMs);
// It should have stopped
Thread.sleep(4000L);
assertEquals(finalFailMs, MockShutdownTrash.getMsAtLastAttempt());
}
@Test(groups="yesbackoff", dependsOnGroups="nobackoff")
public void testBackoff() throws Exception {
logger.debug("yesbackoff");
final Manager rm = this.locator.getManager();
VM[] allvms = rm.getGlobalAll();
assertEquals(0, allvms.length);
MockShutdownTrash.resetFailCount();
final Caller caller = this.populator().getCaller();
final CreateResult result =
rm.create(this.populator().getCreateRequest("suite:backoff:yesbackoff"),
caller);
final VM[] vms = result.getVMs();
assertEquals(1, vms.length);
assertNotNull(vms[0]);
logger.info("Leased vm '" + vms[0].getID() + '\'');
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
Thread.sleep(2000L);
assertEquals(0, MockShutdownTrash.getFailCount());
// Fail at killing the instance:
MockShutdownTrash.setFail(true);
logger.warn("Set to fail.");
rm.trash(vms[0].getID(), Manager.INSTANCE, caller);
Thread.sleep(2000L);
// Check that it is at least trying to terminate the node:
int lastFailCount = MockShutdownTrash.getFailCount();
assertFalse(0 == lastFailCount);
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
allvms = rm.getGlobalAll();
assertEquals(1, allvms.length);
long prevFailMs = MockShutdownTrash.getMsAtLastAttempt();
assertFalse(0 == prevFailMs);
Thread.sleep(4000L);
long nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
assertFalse(nextFailMs == prevFailMs);
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
allvms = rm.getGlobalAll();
assertEquals(1, allvms.length);
long markerTime1 = prevFailMs;
Thread.sleep(2100L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(2300L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(1900L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(2100L);
assertEquals(5, MockShutdownTrash.getFailCount());
Thread.sleep(5000L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(4100L);
assertEquals(6, MockShutdownTrash.getFailCount());
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(4300L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(4900L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(3100L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(4300L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
assertEquals(7, MockShutdownTrash.getFailCount());
Thread.sleep(5100L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
prevFailMs = nextFailMs;
nextFailMs = 0;
Thread.sleep(6300L);
nextFailMs = MockShutdownTrash.getMsAtLastAttempt();
logger.debug("fail difference: " + (nextFailMs - prevFailMs));
assertEquals(8, MockShutdownTrash.getFailCount());
}
}