use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ClusterConfigurationServiceDUnitTest method testSharedConfigurationService.
@Test
public void testSharedConfigurationService() throws Exception {
// Start the Locator and wait for shared configuration to be available
final String testGroup = "G1";
final String clusterLogLevel = "error";
final String groupLogLevel = "fine";
final String testName = getName();
final VM locator1Vm = getHost(0).getVM(1);
final VM dataMemberVm = getHost(0).getVM(2);
final VM locator2Vm = getHost(0).getVM(3);
final int[] ports = getRandomAvailableTCPPorts(3);
final int locator1Port = ports[0];
locator1Vm.invoke(() -> {
final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator1");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "info");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, 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";
}
};
waitForCriterion(wc, TIMEOUT, INTERVAL, true);
} catch (IOException e) {
fail("Unable to create a locator with a shared configuration", e);
}
});
XmlEntity xmlEntity = dataMemberVm.invoke(() -> {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
localProps.setProperty(GROUPS, testGroup);
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
DiskStoreFactory dsFactory = cache.createDiskStoreFactory();
File dsDir = new File("dsDir");
if (!dsDir.exists()) {
dsDir.mkdir();
}
dsFactory.setDiskDirs(new File[] { dsDir });
dsFactory.create(DISKSTORENAME);
RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
regionFactory.create(REGION1);
return new XmlEntity(CacheXml.REGION, "name", REGION1);
});
locator1Vm.invoke(() -> {
ClusterConfigurationService sc = InternalLocator.getLocator().getSharedConfiguration();
sc.addXmlEntity(xmlEntity, new String[] { testGroup });
// Modify property and cache attributes
Properties clusterProperties = new Properties();
clusterProperties.setProperty(LOG_LEVEL, clusterLogLevel);
XmlEntity cacheEntity = XmlEntity.builder().withType(CacheXml.CACHE).build();
Map<String, String> cacheAttributes = new HashMap<String, String>();
cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
sc.modifyXmlAndProperties(clusterProperties, cacheEntity, null);
clusterProperties.setProperty(LOG_LEVEL, groupLogLevel);
sc.modifyXmlAndProperties(clusterProperties, cacheEntity, new String[] { testGroup });
// Add a jar
byte[][] jarBytes = new byte[1][];
jarBytes[0] = "Hello".getBytes();
assertTrue(sc.addJarsToThisLocator(new String[] { "foo.jar" }, jarBytes, null));
// Add a jar for the group
jarBytes = new byte[1][];
jarBytes[0] = "Hello".getBytes();
assertTrue(sc.addJarsToThisLocator(new String[] { "bar.jar" }, jarBytes, new String[] { testGroup }));
});
final int locator2Port = ports[1];
// Create another locator in VM2
locator2Vm.invoke(() -> {
final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator2");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "info");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, 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";
}
};
waitForCriterion(wc, TIMEOUT, INTERVAL, true);
} catch (IOException e) {
fail("Unable to create a locator with a shared configuration", e);
}
InternalLocator locator = (InternalLocator) Locator.getLocator();
ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
Map<String, Configuration> entireConfiguration = sharedConfig.getEntireConfiguration();
Configuration clusterConfig = entireConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
assertNotNull(clusterConfig);
assertNotNull(clusterConfig.getJarNames());
assertTrue(clusterConfig.getJarNames().contains("foo.jar"));
assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
assertNotNull(clusterConfig.getCacheXmlContent());
Configuration testGroupConfiguration = entireConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertNotNull(testGroupConfiguration.getJarNames());
assertTrue(testGroupConfiguration.getJarNames().contains("bar.jar"));
assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(groupLogLevel));
assertNotNull(testGroupConfiguration.getCacheXmlContent());
assertTrue(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
Map<String, byte[]> jarData = sharedConfig.getAllJarsFromThisLocator(entireConfiguration.keySet());
String[] jarNames = jarData.keySet().stream().toArray(String[]::new);
byte[][] jarBytes = jarData.values().toArray(new byte[jarNames.length][]);
assertNotNull(jarNames);
assertNotNull(jarBytes);
sharedConfig.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1), new String[] { testGroup });
sharedConfig.removeJars(new String[] { "foo.jar" }, null);
sharedConfig.removeJars(null, null);
});
dataMemberVm.invoke(() -> {
Set<String> groups = new HashSet<String>();
groups.add(testGroup);
ConfigurationRequest configRequest = new ConfigurationRequest(groups);
ConfigurationResponse configResponse = (ConfigurationResponse) new TcpClient().requestToServer(InetAddress.getByName("localhost"), locator2Port, configRequest, 1000);
assertNotNull(configResponse);
Map<String, Configuration> requestedConfiguration = configResponse.getRequestedConfiguration();
Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
assertNotNull(clusterConfiguration);
assertTrue(configResponse.getJarNames().length == 0);
assertTrue(configResponse.getJars().length == 0);
assertTrue(clusterConfiguration.getJarNames().isEmpty());
assertTrue(clusterConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
Configuration testGroupConfiguration = requestedConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertFalse(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
assertTrue(testGroupConfiguration.getJarNames().isEmpty());
assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL).equals(groupLogLevel));
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Map<InternalDistributedMember, Collection<String>> locatorsWithSharedConfiguration = cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
assertFalse(locatorsWithSharedConfiguration.isEmpty());
assertTrue(locatorsWithSharedConfiguration.size() == 2);
Set<InternalDistributedMember> locatorMembers = locatorsWithSharedConfiguration.keySet();
for (InternalDistributedMember locatorMember : locatorMembers) {
System.out.println(locatorMember);
}
return null;
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class RollingUpgrade2DUnitTest method createRegion.
public static void createRegion(GemFireCache cache, String regionName, RegionShortcut shortcut) throws Exception {
RegionFactory rf = ((GemFireCacheImpl) cache).createRegionFactory(shortcut);
System.out.println("created region " + rf.create(regionName));
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ForceInvalidateEvictionDUnitTest method createClient.
private void createClient(VM vm, final int port) {
final String name = getUniqueName();
final Host host = Host.getHost(0);
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(host), port);
pf.setSubscriptionEnabled(true);
pf.create(name);
RegionFactory rf = new RegionFactory();
rf.setOffHeap(isOffHeapEnabled());
rf.setScope(Scope.LOCAL);
rf.setPoolName(name);
Region region = rf.create(name);
region.registerInterest("ALL_KEYS");
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ForceInvalidateEvictionDUnitTest method createAccessor.
private void createAccessor(VM vm, final boolean allContent) {
final String name = getUniqueName();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
RegionFactory rf = new RegionFactory();
rf.setOffHeap(isOffHeapEnabled());
rf.setDataPolicy(DataPolicy.PARTITION);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(5);
paf.setLocalMaxMemory(0);
rf.setPartitionAttributes(paf.create());
rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1));
rf.setConcurrencyChecksEnabled(false);
if (allContent) {
// rf.initCacheListeners(new CacheListener [] { new MyListener()});
rf.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
}
rf.create(name);
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class QueryDataDUnitTest method testErrors.
@Test
public void testErrors() throws Exception {
this.managerVM.invoke(this.testName.getMethodName(), () -> {
DistributedSystemMXBean distributedSystemMXBean = this.managementTestRule.getSystemManagementService().getDistributedSystemMXBean();
String invalidQuery = "SELECT * FROM " + PARTITIONED_REGION_NAME1;
String invalidQueryResult = distributedSystemMXBean.queryData(invalidQuery, null, 2);
assertThat(invalidQueryResult, isJson(withJsonPath("$.message", equalTo(QUERY__MSG__INVALID_QUERY.toLocalizedString("Region mentioned in query probably missing /")))));
String nonexistentRegionName = this.testName.getMethodName() + "_NONEXISTENT_REGION";
String regionsNotFoundQuery = "SELECT * FROM /" + nonexistentRegionName + " r1, PARTITIONED_REGION_NAME2 r2 WHERE r1.ID = r2.ID";
String regionsNotFoundResult = distributedSystemMXBean.queryData(regionsNotFoundQuery, null, 2);
assertThat(regionsNotFoundResult, isJson(withJsonPath("$.message", equalTo(QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString("/" + nonexistentRegionName)))));
String regionName = this.testName.getMethodName() + "_REGION";
String regionsNotFoundOnMembersQuery = "SELECT * FROM /" + regionName;
RegionFactory regionFactory = this.managementTestRule.getCache().createRegionFactory(RegionShortcut.REPLICATE);
regionFactory.create(regionName);
String regionsNotFoundOnMembersResult = distributedSystemMXBean.queryData(regionsNotFoundOnMembersQuery, member1.getId(), 2);
assertThat(regionsNotFoundOnMembersResult, isJson(withJsonPath("$.message", equalTo(QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBERS.toLocalizedString("/" + regionName)))));
String joinMissingMembersQuery = QUERIES[1];
String joinMissingMembersResult = distributedSystemMXBean.queryData(joinMissingMembersQuery, null, 2);
assertThat(joinMissingMembersResult, isJson(withJsonPath("$.message", equalTo(QUERY__MSG__JOIN_OP_EX.toLocalizedString()))));
});
}
Aggregations