Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
necessary suites.common changes
Browse files Browse the repository at this point in the history
  • Loading branch information
timf committed Nov 15, 2010
1 parent b45edbf commit a9d155d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
Expand Up @@ -20,9 +20,13 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.google.gson.Gson;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
Expand All @@ -31,9 +35,11 @@
import org.globus.workspace.ReturnException;
import org.globus.workspace.WorkspaceException;
import org.globus.workspace.WorkspaceUtil;
import org.globus.workspace.remoting.admin.VmmNode;
import org.globus.workspace.testing.utils.ReprPopulator;
import org.nimbustools.api.brain.ModuleLocator;
import org.nimbustools.api.brain.NimbusHomePathResolver;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterMethod;
Expand All @@ -52,10 +58,11 @@ public abstract class NimbusTestBase extends AbstractTestNGSpringContextTests {
// STATIC VARIABLES
// -----------------------------------------------------------------------------------------

private static final String MODULE_LOCATOR_BEAN_NAME = "nimbus-brain.ModuleLocator";
protected static final String MODULE_LOCATOR_BEAN_NAME = "nimbus-brain.ModuleLocator";
private static final String DATA_SOURCE_BEAN_NAME = "other.MainDataSource";
private static final String TIMER_MANAGER_BEAN_NAME = "other.timerManager";

private static final String REMOTING_NATIVE_PROPERTY = "org.newsclub.net.unix.library.path";

public static final String FORCE_SUITES_DIR_PATH = "nimbus.servicetestsuites.abspath";
public static final String NO_TEARDOWN = "nimbus.servicetestsuites.noteardown";
private static final String LOG_SEP =
Expand Down Expand Up @@ -89,25 +96,23 @@ public abstract class NimbusTestBase extends AbstractTestNGSpringContextTests {
// @Overrides AbstractTestNGSpringContextTests
// -----------------------------------------------------------------------------------------

@Override
@BeforeClass(alwaysRun=true)
protected void springTestContextPrepareTestInstance() throws Exception {
this.suiteSetup();

super.springTestContextPrepareTestInstance();
}

@Override
@BeforeMethod(alwaysRun=true)
protected void springTestContextBeforeTestMethod(Method testMethod)
throws Exception {
super.springTestContextBeforeTestMethod(testMethod);

//Looked up before each test method in case @DirtiesContext was used in previous method
this.locator = (ModuleLocator) applicationContext.getBean(MODULE_LOCATOR_BEAN_NAME);
this.setUpVmms();
}

@Override
@AfterMethod(alwaysRun=true)
protected void springTestContextAfterTestMethod(Method testMethod)
throws Exception {
Expand All @@ -128,7 +133,7 @@ protected void springTestContextAfterTestMethod(Method testMethod)
// -----------------------------------------------------------------------------------------

/**
* Set up logger and var directory for this test suite.
* Set up logger, lib-native, and var directory for this test suite.
*
* Configures NIMBUS_HOME via system property.
*
Expand Down Expand Up @@ -161,10 +166,33 @@ protected void suiteSetup() throws Exception {
this.setUpVarDir(vardir, setupExe);
}

String libNativePath = nimbusHome + "/services/lib-native";
System.setProperty(REMOTING_NATIVE_PROPERTY, libNativePath);

logger.debug(LOG_SEP + "\n*** SUITE SETUP DONE (tests will begin): " +
this.getClass().getSimpleName() + LOG_SEP);
}

protected void setUpVmms() throws RemoteException {

boolean active = true;
String nodePool = "default";
int nodeMemory = 2048;
String net = "*";
boolean vacant = true;

Gson gson = new Gson();
List<VmmNode> nodes = new ArrayList<VmmNode>(4);
nodes.add(new VmmNode("fakehost1", active, nodePool, nodeMemory, net, vacant));
nodes.add(new VmmNode("fakehost2", active, nodePool, nodeMemory, net, vacant));
nodes.add(new VmmNode("fakehost3", active, nodePool, nodeMemory, net, vacant));
nodes.add(new VmmNode("fakehost4", active, nodePool, nodeMemory, net, vacant));

final String nodesJson = gson.toJson(nodes);
RemoteNodeManagement rnm = this.locator.getNodeManagement();
rnm.addNodes(nodesJson);
}

/**
* Remove var directory used in this test suite. Intended to be called from
* your subclass's @AfterSuite method.
Expand Down
Expand Up @@ -21,7 +21,6 @@

public class NimbusTestContextLoader extends AbstractContextLoader {

@Override
protected String getResourceSuffix() {
return "-main.xml";
}
Expand Down
Expand Up @@ -19,30 +19,29 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
import org.testng.annotations.Test;

public class ResourcepoolEntryTest {

@Test
public void testPercentEmpty() {
ResourcepoolEntry re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 2048, 0, "*");
ResourcepoolEntry re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 2048, 0, "*", true);
assertEquals(re.percentEmpty(), 50);
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 1024, 0, "*");
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 1024, 0, "*", true);
assertEquals(re.percentEmpty(), 25);
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 0, 0, "*");
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 0, 0, "*", true);
assertEquals(re.percentEmpty(), 0);
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 1, 0, "*");
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 1, 0, "*", true);
if (re.percentEmpty() == 0) {
fail();
}
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 4096, 0, "*");
re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 4096, 0, "*", true);
assertEquals(re.percentEmpty(), 100);
}

@Test(expectedExceptions=IllegalStateException.class)
public void testPercentEmptyIllegal() {
ResourcepoolEntry re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 4097, 0, "*");
ResourcepoolEntry re = new ResourcepoolEntry("aResourcePool", "ahostname", 4096, 4097, 0, "*", true);
re.percentEmpty();
}
}

0 comments on commit a9d155d

Please sign in to comment.