use of org.apache.geode.test.dunit.rules.ServerStarterRule in project geode by apache.
the class ClassPathLoaderIntegrationTest method testDeployWithExistingDependentJars.
@Test
public void testDeployWithExistingDependentJars() throws Exception {
ClassBuilder classBuilder = new ClassBuilder();
final File parentJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitAParent.v1.jar");
final File usesJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitUses.v1.jar");
final File functionJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitFunction.v1.jar");
// Write out a JAR files.
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.parent;");
stringBuffer.append("public class JarDeployerDUnitParent {");
stringBuffer.append("public String getValueParent() {");
stringBuffer.append("return \"PARENT\";}}");
byte[] jarBytes = classBuilder.createJarFromClassContent("jddunit/parent/JarDeployerDUnitParent", stringBuffer.toString());
FileOutputStream outStream = new FileOutputStream(parentJarFile);
outStream.write(jarBytes);
outStream.close();
stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.uses;");
stringBuffer.append("public class JarDeployerDUnitUses {");
stringBuffer.append("public String getValueUses() {");
stringBuffer.append("return \"USES\";}}");
jarBytes = classBuilder.createJarFromClassContent("jddunit/uses/JarDeployerDUnitUses", stringBuffer.toString());
outStream = new FileOutputStream(usesJarFile);
outStream.write(jarBytes);
outStream.close();
stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.function;");
stringBuffer.append("import jddunit.parent.JarDeployerDUnitParent;");
stringBuffer.append("import jddunit.uses.JarDeployerDUnitUses;");
stringBuffer.append("import org.apache.geode.cache.execute.Function;");
stringBuffer.append("import org.apache.geode.cache.execute.FunctionContext;");
stringBuffer.append("public class JarDeployerDUnitFunction extends JarDeployerDUnitParent implements Function {");
stringBuffer.append("private JarDeployerDUnitUses uses = new JarDeployerDUnitUses();");
stringBuffer.append("public boolean hasResult() {return true;}");
stringBuffer.append("public void execute(FunctionContext context) {context.getResultSender().lastResult(getValueParent() + \":\" + uses.getValueUses());}");
stringBuffer.append("public String getId() {return \"JarDeployerDUnitFunction\";}");
stringBuffer.append("public boolean optimizeForWrite() {return false;}");
stringBuffer.append("public boolean isHA() {return false;}}");
ClassBuilder functionClassBuilder = new ClassBuilder();
functionClassBuilder.addToClassPath(parentJarFile.getAbsolutePath());
functionClassBuilder.addToClassPath(usesJarFile.getAbsolutePath());
jarBytes = functionClassBuilder.createJarFromClassContent("jddunit/function/JarDeployerDUnitFunction", stringBuffer.toString());
outStream = new FileOutputStream(functionJarFile);
outStream.write(jarBytes);
outStream.close();
ServerStarterRule serverStarterRule = new ServerStarterRule(temporaryFolder.getRoot());
serverStarterRule.startServer();
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();
Execution execution = FunctionService.onMember(distributedSystem.getDistributedMember());
ResultCollector resultCollector = execution.execute("JarDeployerDUnitFunction");
@SuppressWarnings("unchecked") List<String> result = (List<String>) resultCollector.getResult();
assertEquals("PARENT:USES", result.get(0));
serverStarterRule.after();
}
use of org.apache.geode.test.dunit.rules.ServerStarterRule in project geode by apache.
the class PeerAuthenticatorDUnitTest method testPeerAuthenticator.
@Test
public void testPeerAuthenticator() throws Exception {
int locatorPort = lsRule.getMember(0).getPort();
Properties server1Props = new Properties();
server1Props.setProperty("security-username", "user");
server1Props.setProperty("security-password", "user");
lsRule.startServerVM(1, server1Props, locatorPort);
Properties server2Props = new Properties();
server2Props.setProperty("security-username", "bogus");
server2Props.setProperty("security-password", "user");
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
ServerStarterRule serverStarter = new ServerStarterRule();
LocatorServerStartupRule.serverStarter = serverStarter;
assertThatThrownBy(() -> serverStarter.startServer(server2Props, locatorPort)).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
});
}
use of org.apache.geode.test.dunit.rules.ServerStarterRule in project geode by apache.
the class PeerSecurityWithEmbeddedLocatorDUnitTest method testPeerAuthenticator.
@Test
public void testPeerAuthenticator() throws Exception {
int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
Properties server0Props = new Properties();
server0Props.setProperty(SECURITY_PEER_AUTHENTICATOR, DummyAuthenticator.class.getName());
server0Props.setProperty("start-locator", "localhost[" + locatorPort + "]");
lsRule.startServerVM(0, server0Props);
Properties server1Props = new Properties();
server1Props.setProperty("security-username", "user");
server1Props.setProperty("security-password", "user");
lsRule.startServerVM(1, server1Props, locatorPort);
Properties server2Props = new Properties();
server2Props.setProperty("security-username", "bogus");
server2Props.setProperty("security-password", "user");
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
ServerStarterRule serverStarter = new ServerStarterRule();
LocatorServerStartupRule.serverStarter = serverStarter;
assertThatThrownBy(() -> serverStarter.startServer(server2Props, locatorPort)).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
});
}
use of org.apache.geode.test.dunit.rules.ServerStarterRule in project geode by apache.
the class ClassPathLoaderIntegrationTest method deployNewVersionOfFunctionOverOldVersion.
@Test
public void deployNewVersionOfFunctionOverOldVersion() throws Exception {
File jarVersion1 = createVersionOfJar("Version1", "MyFunction", "MyJar.jar");
File jarVersion2 = createVersionOfJar("Version2", "MyFunction", "MyJar.jar");
ServerStarterRule serverStarterRule = new ServerStarterRule(temporaryFolder.getRoot());
serverStarterRule.startServer();
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();
ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar", FileUtils.readFileToByteArray(jarVersion1));
assertThatClassCanBeLoaded("jddunit.function.MyFunction");
Execution execution = FunctionService.onMember(distributedSystem.getDistributedMember());
List<String> result = (List<String>) execution.execute("MyFunction").getResult();
assertThat(result.get(0)).isEqualTo("Version1");
ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar", FileUtils.readFileToByteArray(jarVersion2));
result = (List<String>) execution.execute("MyFunction").getResult();
assertThat(result.get(0)).isEqualTo("Version2");
serverStarterRule.after();
}
use of org.apache.geode.test.dunit.rules.ServerStarterRule in project geode by apache.
the class PeerSecurityWithEmbeddedLocatorDUnitTest method testPeerSecurityManager.
@Test
public void testPeerSecurityManager() throws Exception {
int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
Properties server0Props = new Properties();
server0Props.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
server0Props.setProperty("start-locator", "localhost[" + locatorPort + "]");
lsRule.startServerVM(0, server0Props);
Properties server1Props = new Properties();
server1Props.setProperty("security-username", "cluster");
server1Props.setProperty("security-password", "cluster");
lsRule.startServerVM(1, server1Props, locatorPort);
Properties server2Props = new Properties();
server2Props.setProperty("security-username", "user");
server2Props.setProperty("security-password", "wrongPwd");
VM server2 = getHost(0).getVM(2);
server2.invoke(() -> {
ServerStarterRule serverStarter = new ServerStarterRule();
LocatorServerStartupRule.serverStarter = serverStarter;
assertThatThrownBy(() -> serverStarter.startServer(server2Props, locatorPort)).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Security check failed. Authentication error");
});
}
Aggregations