Search in sources :

Example 1 with Stock

use of org.apache.geode.management.internal.cli.domain.Stock in project geode by apache.

the class IndexCommandsDUnitTest method setupSystem.

private void setupSystem() {
    disconnectAllFromDS();
    setUpJmxManagerOnVm0ThenConnect(null);
    final String parRegName = "StocksParReg";
    final VM manager = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    manager.invoke(new SerializableCallable() {

        public Object call() {
            Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
            parReg.put("VMW", new Stock("VMW", 98));
            return parReg.put("APPL", new Stock("APPL", 600));
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties props = new Properties();
            props.setProperty(NAME, VM1Name);
            props.setProperty(GROUPS, group1);
            getSystem(props);
            Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
            parReg.put("MSFT", new Stock("MSFT", 27));
            return parReg.put("GOOG", new Stock("GOOG", 540));
        }
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) Stock(org.apache.geode.management.internal.cli.domain.Stock) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 2 with Stock

use of org.apache.geode.management.internal.cli.domain.Stock in project geode by apache.

the class IndexCommandsDUnitTest method setupSystemPersist.

private void setupSystemPersist() {
    disconnectAllFromDS();
    setUpJmxManagerOnVm0ThenConnect(null);
    final String parRegName = "StocksParReg";
    final VM manager = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    manager.invoke(new SerializableCallable() {

        public Object call() {
            Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
            parReg.put("VMW", new Stock("VMW", 98));
            Region parRegPers = createParRegWithPersistence(parRegPersName, "testCreateIndexDiskstore1", "testCreateIndexDiskDir1");
            Region repRegPers = createRepRegWithPersistence(repRegPersName, "testCreateIndexDiskstore1", "testCreateIndexDiskDir1");
            return parReg.put("APPL", new Stock("APPL", 600));
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties props = new Properties();
            props.setProperty(NAME, VM1Name);
            props.setProperty(GROUPS, group1);
            getSystem(props);
            Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
            parReg.put("MSFT", new Stock("MSFT", 27));
            Region parRegPers = createParRegWithPersistence(parRegPersName, "testCreateIndexDiskstore2", "testCreateIndexDiskDir2");
            Region repRegPers = createRepRegWithPersistence(repRegPersName, "testCreateIndexDiskstore2", "testCreateIndexDiskDir2");
            return parReg.put("GOOG", new Stock("GOOG", 540));
        }
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) Stock(org.apache.geode.management.internal.cli.domain.Stock) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with Stock

use of org.apache.geode.management.internal.cli.domain.Stock in project geode by apache.

the class IndexCommandsDUnitTest method testCreateDestroyUpdatesSharedConfig.

/**
   * Asserts that creating and destroying indexes correctly updates the shared configuration.
   */
// GEODE-1954
@Category(FlakyTest.class)
@Test
public void testCreateDestroyUpdatesSharedConfig() {
    disconnectAllFromDS();
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    jmxPort = ports[0];
    httpPort = ports[1];
    try {
        jmxHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ignore) {
        jmxHost = "localhost";
    }
    final String regionName = "testIndexSharedConfigRegion";
    final String groupName = "testIndexSharedConfigGroup";
    final Properties locatorProps = new Properties();
    locatorProps.setProperty(NAME, "Locator");
    locatorProps.setProperty(MCAST_PORT, "0");
    locatorProps.setProperty(LOG_LEVEL, "fine");
    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
    locatorProps.setProperty(JMX_MANAGER, "true");
    locatorProps.setProperty(JMX_MANAGER_START, "true");
    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            final File locatorLogFile = new File("locator-" + locatorPort + ".log");
            try {
                final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
                WaitCriterion wc = new WaitCriterion() {

                    @Override
                    public boolean done() {
                        return locator.isSharedConfigurationRunning();
                    }

                    @Override
                    public String description() {
                        return "Waiting for shared configuration to be started";
                    }
                };
                Wait.waitForCriterion(wc, 5000, 500, true);
            } catch (IOException ioex) {
                fail("Unable to create a locator with a shared configuration");
            }
        }
    });
    // Start the default manager
    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
    // Create a cache in VM 1
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            getSystem(localProps);
            assertNotNull(getCache());
            Region parReg = createParReg(regionName, getCache(), String.class, Stock.class);
            parReg.put("VMW", new Stock("VMW", 98));
        }
    });
    // Test creating the index
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_INDEX);
    commandStringBuilder.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
    commandStringBuilder.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
    commandStringBuilder.addOption(CliStrings.CREATE_INDEX__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.CREATE_INDEX__REGION, "\"/" + regionName + " p\"");
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the index exists in the shared config
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
            String xmlFromConfig;
            try {
                xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
                assertTrue(xmlFromConfig.contains(indexName));
            } catch (Exception e) {
                Assert.fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Restart a member and make sure he gets the shared configuration
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            getCache().close();
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
            getSystem(localProps);
            Cache cache = getCache();
            assertNotNull(cache);
            Region region = cache.getRegion(regionName);
            assertNotNull(region);
            Index index = cache.getQueryService().getIndex(region, indexName);
            assertNotNull(index);
        }
    });
    // Test destroying the index
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
    commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
    commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__REGION, "/" + regionName);
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the index was removed from the shared config
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
            String xmlFromConfig;
            try {
                xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
                assertFalse(xmlFromConfig.contains(indexName));
            } catch (Exception e) {
                Assert.fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Restart the data member cache to make sure that the index is destroyed.
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            getCache().close();
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
            getSystem(localProps);
            Cache cache = getCache();
            assertNotNull(cache);
            Region region = cache.getRegion(regionName);
            assertNotNull(region);
            Index index = cache.getQueryService().getIndex(region, indexName);
            assertNull(index);
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Index(org.apache.geode.cache.query.Index) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) File(java.io.File) Stock(org.apache.geode.management.internal.cli.domain.Stock) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Properties (java.util.Properties)3 Region (org.apache.geode.cache.Region)3 Stock (org.apache.geode.management.internal.cli.domain.Stock)3 VM (org.apache.geode.test.dunit.VM)3 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 File (java.io.File)1 Cache (org.apache.geode.cache.Cache)1 Index (org.apache.geode.cache.query.Index)1 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)1 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)1 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)1 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1