Search in sources :

Example 6 with ClassBuilder

use of org.apache.geode.internal.ClassBuilder in project geode by apache.

the class ClusterConfigTestBase method createJarFileWithClass.

protected String createJarFileWithClass(String className, String jarName, File dir) throws IOException {
    File jarFile = new File(dir, jarName);
    new ClassBuilder().writeJarFromName(className, jarFile);
    return jarFile.getCanonicalPath();
}
Also used : ClassBuilder(org.apache.geode.internal.ClassBuilder) File(java.io.File)

Example 7 with ClassBuilder

use of org.apache.geode.internal.ClassBuilder in project geode by apache.

the class ClusterConfigurationServiceEndToEndDUnitTest method createAsyncEventQueue.

private void createAsyncEventQueue(final String queueName) throws IOException {
    String queueCommandsJarName = "testEndToEndSC-QueueCommands.jar";
    final File jarFile = new File(queueCommandsJarName);
    try {
        ClassBuilder classBuilder = new ClassBuilder();
        byte[] jarBytes = classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener", "package com.qcdunit;" + "import java.util.List; import java.util.Properties;" + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;" + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;" + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {" + "Properties props;" + "public boolean processEvents(List<AsyncEvent> events) { return true; }" + "public void close() {}" + "public void init(final Properties props) {this.props = props;}" + "public Properties getConfig() {return this.props;}}");
        FileUtils.writeByteArrayToFile(jarFile, jarBytes);
        CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
        csb.addOption(CliStrings.DEPLOY__JAR, queueCommandsJarName);
        executeAndVerifyCommand(csb.getCommandString());
        csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "100");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, "200");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, "4");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION, "true");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS, "true");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY, "false");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY, OrderPolicy.KEY.toString());
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "true");
        csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL, "true");
        executeAndVerifyCommand(csb.getCommandString());
    } finally {
        FileUtils.deleteQuietly(jarFile);
    }
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) ClassBuilder(org.apache.geode.internal.ClassBuilder) File(java.io.File)

Example 8 with ClassBuilder

use of org.apache.geode.internal.ClassBuilder in project geode by apache.

the class ClusterConfigurationServiceEndToEndDUnitTest method postSetUpCliCommandTestBase.

@Override
public final void postSetUpCliCommandTestBase() throws Exception {
    disconnectAllFromDS();
    addIgnoredException("EntryDestroyedException");
    serverNames = new HashSet<>();
    jarFileNames = new HashSet<>();
    this.classBuilder = new ClassBuilder();
    Object[] result = setup();
    int locatorPort = (Integer) result[0];
    this.jmxHost = (String) result[1];
    this.jmxPort = (Integer) result[2];
    this.httpPort = (Integer) result[3];
    this.locatorString = "localHost[" + locatorPort + "]";
}
Also used : ClassBuilder(org.apache.geode.internal.ClassBuilder)

Example 9 with ClassBuilder

use of org.apache.geode.internal.ClassBuilder in project geode by apache.

the class IncrementalBackupDUnitTest method testBackupUserDeployedJarFiles.

/**
   * Successful if a user deployed jar file is included as part of the backup.
   */
@Test
public void testBackupUserDeployedJarFiles() throws Exception {
    final String jarName = "BackupJarDeploymentDUnit";
    final String jarNameRegex = ".*" + jarName + ".*";
    final ClassBuilder classBuilder = new ClassBuilder();
    final byte[] classBytes = classBuilder.createJarFromName(jarName);
    VM vm0 = Host.getHost(0).getVM(0);
    /*
     * Deploy a "dummy" jar to the VM.
     */
    File deployedJarFile = vm0.invoke(() -> {
        DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, classBytes);
        return deployedJar.getFile();
    });
    assertTrue(deployedJarFile.exists());
    /*
     * Perform backup. Make sure it is successful.
     */
    assertBackupStatus(baseline(vm0));
    /*
     * Make sure the user deployed jar is part of the backup.
     */
    Collection<File> memberDeployedJarFiles = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), getMemberId(vm0)), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberDeployedJarFiles.isEmpty());
    // Shut down our member so we can perform a restore
    PersistentID id = getPersistentID(vm0);
    closeCache(vm0);
    /*
     * Get the VM's user directory.
     */
    final String vmDir = vm0.invoke(() -> System.getProperty("user.dir"));
    File backupDir = getBackupDirForMember(getBaselineDir(), getMemberId(vm0));
    vm0.bounce();
    /*
     * Cleanup "dummy" jar from file system.
     */
    Pattern pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File("."), pattern);
    // Execute the restore
    performRestore(new File(id.getDirectory()), backupDir);
    /*
     * Make sure the user deployed jar is part of the restore.
     */
    Collection<File> restoredJars = FileUtils.listFiles(new File(vmDir), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(restoredJars.isEmpty());
    List<String> restoredJarNames = new LinkedList<>();
    TransformUtils.transform(memberDeployedJarFiles, restoredJarNames, TransformUtils.fileNameTransformer);
    for (String name : restoredJarNames) {
        assertTrue(name.contains(jarName));
    }
    // Restart the member
    openCache(vm0);
    /*
     * Remove the "dummy" jar from the VM.
     */
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            for (DeployedJar jarClassLoader : ClassPathLoader.getLatest().getJarDeployer().findDeployedJars()) {
                if (jarClassLoader.getJarName().startsWith(jarName)) {
                    ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
                }
            }
            return null;
        }
    });
    /*
     * Cleanup "dummy" jar from file system.
     */
    pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File(vmDir), pattern);
}
Also used : DeployedJar(org.apache.geode.internal.DeployedJar) Pattern(java.util.regex.Pattern) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) ClassBuilder(org.apache.geode.internal.ClassBuilder) LinkedList(java.util.LinkedList) AdminException(org.apache.geode.admin.AdminException) IOException(java.io.IOException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) File(java.io.File) PersistentID(org.apache.geode.cache.persistence.PersistentID) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 10 with ClassBuilder

use of org.apache.geode.internal.ClassBuilder in project geode by apache.

the class DeployCommandRedeployDUnitTest method createJarWithFunctionB.

private File createJarWithFunctionB(String version) throws Exception {
    URL classTemplateUrl = DeployCommandRedeployDUnitTest.class.getResource("DeployCommandRedeployDUnitTest_FunctionBTemplate");
    assertThat(classTemplateUrl).isNotNull();
    String classContents = FileUtils.readFileToString(new File(classTemplateUrl.toURI()), "UTF-8");
    classContents = classContents.replaceAll("PACKAGE_B", PACKAGE_B);
    classContents = classContents.replaceAll("FUNCTION_B", FUNCTION_B);
    classContents = classContents.replaceAll("VERSION", version);
    File jar = new File(lsRule.getTempFolder().newFolder(JAR_NAME_B + version), this.JAR_NAME_B);
    ClassBuilder functionClassBuilder = new ClassBuilder();
    functionClassBuilder.writeJarFromContent("jddunit/function/" + FUNCTION_B, classContents, jar);
    return jar;
}
Also used : ClassBuilder(org.apache.geode.internal.ClassBuilder) File(java.io.File) URL(java.net.URL)

Aggregations

ClassBuilder (org.apache.geode.internal.ClassBuilder)13 File (java.io.File)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)4 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 VM (org.apache.geode.test.dunit.VM)4 Properties (java.util.Properties)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 IOException (java.io.IOException)2 URL (java.net.URL)2 Cache (org.apache.geode.cache.Cache)2 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 Category (org.junit.experimental.categories.Category)2 UnknownHostException (java.net.UnknownHostException)1 LinkedList (java.util.LinkedList)1 Pattern (java.util.regex.Pattern)1 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)1 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)1