Search in sources :

Example 1 with ServerStarterRule

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();
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem) ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) Execution(org.apache.geode.cache.execute.Execution) FileOutputStream(java.io.FileOutputStream) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) List(java.util.List) File(java.io.File) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ServerStarterRule

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");
    });
}
Also used : ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) VM(org.apache.geode.test.dunit.VM) Properties(java.util.Properties) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with ServerStarterRule

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");
    });
}
Also used : ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) DummyAuthenticator(org.apache.geode.security.templates.DummyAuthenticator) VM(org.apache.geode.test.dunit.VM) Properties(java.util.Properties) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with ServerStarterRule

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();
}
Also used : ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) Execution(org.apache.geode.cache.execute.Execution) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) List(java.util.List) File(java.io.File) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with ServerStarterRule

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");
    });
}
Also used : ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) VM(org.apache.geode.test.dunit.VM) Properties(java.util.Properties) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ServerStarterRule (org.apache.geode.test.dunit.rules.ServerStarterRule)5 Test (org.junit.Test)5 Properties (java.util.Properties)3 VM (org.apache.geode.test.dunit.VM)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)3 File (java.io.File)2 List (java.util.List)2 Execution (org.apache.geode.cache.execute.Execution)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 FileOutputStream (java.io.FileOutputStream)1 ResultCollector (org.apache.geode.cache.execute.ResultCollector)1 DummyAuthenticator (org.apache.geode.security.templates.DummyAuthenticator)1