geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
@Test
  public void testCreateRegionWithPartitionResolver() throws IOException {
    setUpJmxManagerOnVm0ThenConnect(null);
    VM vm = Host.getHost(0).getVM(1);
    // Create a cache in vm 1
    vm.invoke(() -> assertNotNull(getCache()));

    ClassBuilder classBuilder = new ClassBuilder();
    // classBuilder.addToClassPath(".");
    final File prJarFile = new File(temporaryFolder.getRoot().getCanonicalPath() + File.separator,
        "myPartitionResolver.jar");
    this.filesToBeDeleted.add(prJarFile.getAbsolutePath());
    String PR_STRING = " package com.cadrdunit;"
        + " public class TestPartitionResolver implements org.apache.geode.cache.PartitionResolver { "
        + "   @Override" + "   public void close() {" + "   }" + "   @Override"
        + "   public Object getRoutingObject(org.apache.geode.cache.EntryOperation opDetails) { "
        + "    return null; " + "   }" + "   @Override" + "   public String getName() { "
        + "    return \"TestPartitionResolver\";" + "   }" + " }";
    byte[] jarBytes =
        classBuilder.createJarFromClassContent("com/cadrdunit/TestPartitionResolver", PR_STRING);
    writeJarBytesToFile(prJarFile, jarBytes);

    CommandResult cmdResult = executeCommand("deploy --jar=" + prJarFile.getAbsolutePath());
    assertEquals(Result.Status.OK, cmdResult.getStatus());


    // Create a region with an unrecognized compressor
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "regionWithPartitionResolver");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER,
        "com.cadrdunit.TestPartitionResolver");
    CommandResult cmdResult1 = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult1.getStatus());

    // Assert that our region was not created
    vm.invoke(() -> {
      Region region = getCache().getRegion("regionWithPartitionResolver");
      assertNotNull(region);

      PartitionedRegion pr = (PartitionedRegion) region;
      PartitionAttributes partitionAttributes = pr.getPartitionAttributes();
      assertNotNull(partitionAttributes);
      PartitionResolver partitionResolver = partitionAttributes.getPartitionResolver();
      assertNotNull(partitionResolver);
      assertEquals("TestPartitionResolver", partitionResolver.getName());
    });

    vm.invoke(() -> getCache().getRegion("regionWithPartitionResolver").destroyRegion());
  }
/**
   * Test Description 1. Deploy a JAR with Custom Partition Resolver 2. Create Region with Partition
   * Resolver 3. Region should get created with no Errors 4. Verify Region Partition Attributes for
   * Partition Resolver
   */
Test Description 1. Deploy a JAR with Custom Partition Resolver 2. Create Region with Partition
Resolver 3. Region should get created with no Errors 4. Verify Region Partition Attributes for
Partition Resolver
Test Description 1 . Deploy a JAR with Custom Partition Resolver 2 . Create Region with Partition Resolver 3 . Region should get created with no Errors 4 . Verify Region Partition Attributes for Partition Resolver
@Test
  public void testCreateRegionWithPartitionResolver() throws IOException {
    setUpJmxManagerOnVm0ThenConnect(null);
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(() -> assertNotNull(getCache()));
    ClassBuilder classBuilder = new ClassBuilder();
    final File prJarFile = new File(temporaryFolder.getRoot().getCanonicalPath() + File.separator,
        "myPartitionResolver.jar");
    this.filesToBeDeleted.add(prJarFile.getAbsolutePath());
    String PR_STRING = " package com.cadrdunit;"
        + " public class TestPartitionResolver implements org.apache.geode.cache.PartitionResolver { "
        + "   @Override" + "   public void close() {" + "   }" + "   @Override"
        + "   public Object getRoutingObject(org.apache.geode.cache.EntryOperation opDetails) { "
        + "    return null; " + "   }" + "   @Override" + "   public String getName() { "
        + "    return \"TestPartitionResolver\";" + "   }" + " }";
    byte[] jarBytes =
        classBuilder.createJarFromClassContent("com/cadrdunit/TestPartitionResolver", PR_STRING);
    writeJarBytesToFile(prJarFile, jarBytes);
    CommandResult cmdResult = executeCommand("deploy --jar=" + prJarFile.getAbsolutePath());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "regionWithPartitionResolver");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER,
        "com.cadrdunit.TestPartitionResolver");
    CommandResult cmdResult1 = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult1.getStatus());
    vm.invoke(() -> {
      Region region = getCache().getRegion("regionWithPartitionResolver");
      assertNotNull(region);
      PartitionedRegion pr = (PartitionedRegion) region;
      PartitionAttributes partitionAttributes = pr.getPartitionAttributes();
      assertNotNull(partitionAttributes);
      PartitionResolver partitionResolver = partitionAttributes.getPartitionResolver();
      assertNotNull(partitionResolver);
      assertEquals("TestPartitionResolver", partitionResolver.getName());
    });
    vm.invoke(() -> getCache().getRegion("regionWithPartitionResolver").destroyRegion());
  }
@ Test public void testCreateRegionWithPartitionResolver ( ) throws IOException { setUpJmxManagerOnVm0ThenConnect ( null ) ; VM vm = Host . getHost ( 0 ) . getVM ( 1 ) ; vm . invoke ( ( ) -> assertNotNull ( getCache ( ) ) ) ; ClassBuilder classBuilder = new ClassBuilder ( ) ; final File prJarFile = new File ( temporaryFolder . getRoot ( ) . getCanonicalPath ( ) + File . separator , "myPartitionResolver.jar" ) ; this . filesToBeDeleted . add ( prJarFile . getAbsolutePath ( ) ) ; String PR_STRING = " package com.cadrdunit;" + " public class TestPartitionResolver implements org.apache.geode.cache.PartitionResolver { " + "   @Override" + "   public void close() {" + "   }" + "   @Override" + "   public Object getRoutingObject(org.apache.geode.cache.EntryOperation opDetails) { " + "    return null; " + "   }" + "   @Override" + "   public String getName() { " + "    return \"TestPartitionResolver\";" + "   }" + " }" ; byte [ ] jarBytes = classBuilder . createJarFromClassContent ( "com/cadrdunit/TestPartitionResolver" , PR_STRING ) ; writeJarBytesToFile ( prJarFile , jarBytes ) ; CommandResult cmdResult = executeCommand ( "deploy --jar=" + prJarFile . getAbsolutePath ( ) ) ; assertEquals ( Result . Status . OK , cmdResult . getStatus ( ) ) ; CommandStringBuilder commandStringBuilder = new CommandStringBuilder ( CliStrings . CREATE_REGION ) ; commandStringBuilder . addOption ( CliStrings . CREATE_REGION__REGION , "regionWithPartitionResolver" ) ; commandStringBuilder . addOption ( CliStrings . CREATE_REGION__REGIONSHORTCUT , "PARTITION" ) ; commandStringBuilder . addOption ( CliStrings . CREATE_REGION__PARTITION_RESOLVER , "com.cadrdunit.TestPartitionResolver" ) ; CommandResult cmdResult1 = executeCommand ( commandStringBuilder . toString ( ) ) ; assertEquals ( Result . Status . OK , cmdResult1 . getStatus ( ) ) ; vm . invoke ( ( ) -> { Region region = getCache ( ) . getRegion ( "regionWithPartitionResolver" ) ; assertNotNull ( region ) ; PartitionedRegion pr = ( PartitionedRegion ) region ; PartitionAttributes partitionAttributes = pr . getPartitionAttributes ( ) ; assertNotNull ( partitionAttributes ) ; PartitionResolver partitionResolver = partitionAttributes . getPartitionResolver ( ) ; assertNotNull ( partitionResolver ) ; assertEquals ( "TestPartitionResolver" , partitionResolver . getName ( ) ) ; } ) ; vm . invoke ( ( ) -> getCache ( ) . getRegion ( "regionWithPartitionResolver" ) . destroyRegion ( ) ) ; }
Test Description 1.
Test Description 1 .
// Create a cache in vm 1 // classBuilder.addToClassPath("."); // Create a region with an unrecognized compressor // Assert that our region was not created