This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
/
AsyncRequestMapSuite.java
175 lines (148 loc) · 7.67 KB
/
AsyncRequestMapSuite.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
/*
* Copyright 1999-2010 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.basic;
import org.apache.commons.dbcp.BasicDataSource;
import org.globus.workspace.async.AsyncRequest;
import org.globus.workspace.async.AsyncRequestMap;
import org.globus.workspace.async.AsyncRequestStatus;
import org.globus.workspace.persistence.DataConvert;
import org.globus.workspace.persistence.PersistenceAdapter;
import org.globus.workspace.service.binding.vm.VirtualMachine;
import org.globus.workspace.testing.NimbusTestBase;
import org.globus.workspace.testing.NimbusTestContextLoader;
import org.nimbustools.api.repr.Caller;
import org.nimbustools.api.repr.CreateResult;
import org.nimbustools.api.repr.ctx.Context;
import org.nimbustools.api.repr.vm.NIC;
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;
import org.springframework.core.io.FileSystemResource;
import sun.management.FileSystem;
import java.util.Calendar;
import java.util.Collection;
import java.util.Properties;
import static org.testng.AssertJUnit.*;
@ContextConfiguration(
locations={"file:./service/service/java/tests/suites/basic/home/services/etc/nimbus/workspace-service/other/main.xml"},
loader=NimbusTestContextLoader.class)
public class AsyncRequestMapSuite 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() + "/basic/home";
}
// -----------------------------------------------------------------------------------------
// PREREQ TESTS (if any of these fail, nothing else will work at all)
// -----------------------------------------------------------------------------------------
/**
* Check if ModuleLocator can be retrieved and used at all.
* @throws Exception problem
*/
@Test(groups="prereqs")
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);
}
/**
* Lease a VM and then destroy it.
* @throws Exception problem
*/
@Test(dependsOnGroups="prereqs")
public void persistOne() throws Exception {
logger.debug("persistOne");
final Manager rm = this.locator.getManager();
final Caller caller = this.populator().getCaller();
PersistenceAdapter persistence = (PersistenceAdapter) applicationContext.getBean("nimbus-rm.persistence.PersistenceAdapter");
AsyncRequestMap asyncRequestMap = new AsyncRequestMap(persistence);
// Validate that we have a working AsyncRequestMap. It should be empty
Collection<AsyncRequest> allRequests = asyncRequestMap.getAll();
logger.debug("You have " + allRequests.size() + " requests.");
assert(allRequests.size() == 0);
// Test putting and getting from persistence
String testID = "fake-id";
Double testMaxBid = 42.0;
boolean testSpotinstances = false;
String testGroupID = "fake-group-id";
boolean testIsPersistent = true;
Caller testCaller = this.populator().getSuperuserCaller();
Context context = null;
String testSshKeyName = "fake-ssh-key";
Calendar testCreationTime = Calendar.getInstance();
testCreationTime.setTimeInMillis(424242424242l);
String testNIC = "FakeName;FakeAssociation;FAKEMAC;NetMode;IPmethod;192.168.1.42;192.168.1.1;192.168.1.2;subnetmask;dns;hostname;null;null;null;null";
VirtualMachine testVM = new VirtualMachine();
testVM.setID(42);
testVM.setName("fakename");
testVM.setNetwork(testNIC);
testVM.setPropagateRequired(false);
testVM.setUnPropagateRequired(true);
VirtualMachine[] testBindings = new VirtualMachine[1];
testBindings[0] = testVM;
int testAllocatedVM = 42;
DataConvert dataConvert = new DataConvert(this.locator.getReprFactory());
NIC[] testNICs = dataConvert.getNICs(testVM);
logger.debug("Nics: " + testNICs[0]);
//public AsyncRequest(String id, boolean spotinstances, Double spotPrice, boolean persistent, Caller caller, String groupID, VirtualMachine[] bindings, Context context, NIC[] requestedNics, String sshKeyName, Calendar creationTime) {
AsyncRequest testRequest = new AsyncRequest(testID, testSpotinstances, testMaxBid, testIsPersistent, testCaller, testGroupID, testBindings, context, testNICs, testSshKeyName, testCreationTime);
testRequest.addAllocatedVM(testAllocatedVM);
asyncRequestMap.addOrReplace(testRequest);
logger.debug("Status: " + testRequest.getStatus());
allRequests = asyncRequestMap.getAll();
assert(allRequests != null);
logger.debug("You have " + allRequests.size() + " requests.");
assert(allRequests.size() == 1);
// Note, the persistence layer just dumps the context, so we don't test for it
AsyncRequest gotRequest = asyncRequestMap.getByID(testID);
assertEquals(testID, gotRequest.getId());
assertEquals(testMaxBid, gotRequest.getMaxBid());
assertEquals(testSpotinstances, gotRequest.isSpotRequest());
assertEquals(testGroupID, gotRequest.getGroupID());
assertEquals(testIsPersistent, gotRequest.isPersistent());
assertEquals(testCaller, gotRequest.getCaller());
assertEquals(testSshKeyName, gotRequest.getSshKeyName());
assertEquals(testCreationTime, gotRequest.getCreationTime());
assertEquals(testVM.getID(), gotRequest.getBindings()[0].getID());
assertEquals(testNICs[0].getIpAddress(), gotRequest.getRequestedNics()[0].getIpAddress());
assertEquals(testAllocatedVM, gotRequest.getAllocatedVMs()[0]);
assertEquals(AsyncRequestStatus.OPEN, gotRequest.getStatus());
gotRequest.setStatus(AsyncRequestStatus.ACTIVE);
asyncRequestMap.addOrReplace(gotRequest);
AsyncRequest updatedRequest = asyncRequestMap.getByID(testID);
assertEquals(AsyncRequestStatus.ACTIVE, updatedRequest.getStatus());
assertEquals(testAllocatedVM, updatedRequest.getAllocatedVMs()[0]);
asyncRequestMap.addOrReplace(updatedRequest);
AsyncRequest updatedRequest1 = asyncRequestMap.getByID(testID);
assertEquals(testAllocatedVM, updatedRequest1.getAllocatedVMs()[0]);
}
}