Skip to content

Commit

Permalink
GEODE-7407: Remove AttributesFactory from Test
Browse files Browse the repository at this point in the history
- Fixed some minor warnings.
- Removed references to the deprecated AttributesFactory class from
  the RestAPIsAndInterOpsDUnitTest class.
  • Loading branch information
jujoramos authored Nov 11, 2019
1 parent 2c76bf2 commit 1b66d88
Showing 1 changed file with 72 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientCache;
Expand All @@ -65,13 +63,10 @@
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.internal.LocatorTestBase;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.cache.server.ServerLoadProbe;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
import org.apache.geode.pdx.PdxInstance;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.NetworkUtils;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.RestAPITest;
Expand Down Expand Up @@ -149,37 +144,60 @@ public static Collection<String> data() {
return Arrays.asList("/geode", "/gemfire-api");
}

private String startBridgeServerWithRestService(final String hostName, final String[] groups,
final String locators, final String[] regions, final ServerLoadProbe probe)
@SuppressWarnings("unchecked")
private CacheServer createRegionAndStartCacheServer(String[] regions, Cache cache)
throws IOException {
final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
RegionAttributesCreation regionAttributes = new RegionAttributesCreation();
regionAttributes.setEnableBridgeConflation(true);
regionAttributes.setDataPolicy(DataPolicy.REPLICATE);

// create Cache of given VM and start HTTP service with REST APIs service
for (String region : regions) {
cache.createRegionFactory(regionAttributes).create(region);
}

CacheServer server = cache.addCacheServer();
server.setPort(0);
server.setLoadProbe(CacheServer.DEFAULT_LOAD_PROBE);
server.start();

return server;
}

private int startManager(final String locators, final String[] regions) throws IOException {
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, locators);

props.setProperty(JMX_MANAGER, "true");
props.setProperty(JMX_MANAGER_START, "true");
props.setProperty(JMX_MANAGER_PORT, "0");

final int httpPort = AvailablePortHelper.getRandomAvailableTCPPort();
// Set REST service related configuration
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));

Cache cache = new CacheFactory(props).create();
CacheServer server = createRegionAndStartCacheServer(regions, cache);

return server.getPort();
}

private String startBridgeServerWithRestService(final String hostName, final String locators,
final String[] regions) throws IOException {
final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
// create Cache of given VM and start HTTP service with REST APIs service
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, locators);
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(serverPort));

DistributedSystem ds = getSystem(props);
InternalCache cache = (InternalCache) CacheFactory.create(ds);
InternalCache cache = (InternalCache) new CacheFactory(props).create();
cache.setReadSerializedForTest(true);
AttributesFactory factory = new AttributesFactory();

factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}

CacheServer server = cache.addCacheServer();
server.setPort(0);
server.setGroups(groups);
server.setLoadProbe(probe);
server.start();
CacheServer server = createRegionAndStartCacheServer(regions, cache);

remoteObjects.put(CACHE_KEY, cache);
server.getPort();
Expand All @@ -188,7 +206,7 @@ private String startBridgeServerWithRestService(final String hostName, final Str
}

private void doPutsInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
ClientCache cache = ClientCacheFactory.getAnyInstance();
assertThat(cache).isNotNull();
Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);

Expand Down Expand Up @@ -224,7 +242,7 @@ private void doPutsInClientCache() {
final Person person11 = new Person(104L, "Murali", "Manohar", "Joshi",
DateTimeUtils.createDate(1923, Calendar.APRIL, 25), Gender.MALE);
final Person person12 = new Person(104L, "Lalkrishna", "Parmhansh", "Advani",
DateTimeUtils.createDate(1910, Calendar.JANUARY, 01), Gender.MALE);
DateTimeUtils.createDate(1910, Calendar.JANUARY, 1), Gender.MALE);
final Person person13 = new Person(104L, "Shushma", "kumari", "Swaraj",
DateTimeUtils.createDate(1943, Calendar.AUGUST, 10), Gender.FEMALE);
final Person person14 = new Person(104L, "Arun", "raman", "jetly",
Expand All @@ -234,7 +252,7 @@ private void doPutsInClientCache() {
final Person person16 = new Person(104L, "Shila", "kumari", "Dixit",
DateTimeUtils.createDate(1927, Calendar.FEBRUARY, 15), Gender.FEMALE);

Map<String, Object> userMap = new HashMap<String, Object>();
Map<String, Object> userMap = new HashMap<>();
userMap.put("6", person6);
userMap.put("7", person7);
userMap.put("8", person8);
Expand Down Expand Up @@ -324,7 +342,7 @@ private void doQueryOpsUsingRestApis(String restEndpoint) throws IOException {
}

private void verifyUpdatesInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
ClientCache cache = ClientCacheFactory.getAnyInstance();
assertThat(cache).isNotNull();
Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);

Expand Down Expand Up @@ -583,31 +601,38 @@ private void doGetsUsingRestApis(String restEndpoint) throws IOException {
}

private void createRegionInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
ClientCache cache = ClientCacheFactory.getAnyInstance();
assertThat(cache).isNotNull();
ClientRegionFactory<String, Object> crf =
cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<String, Object> region = crf.create(PEOPLE_REGION_NAME);
crf.create(PEOPLE_REGION_NAME);
}

private void createRegion() {
Cache cache = GemFireCacheImpl.getInstance();
Cache cache = CacheFactory.getAnyInstance();
assertThat(cache).isNotNull();

RegionFactory<String, Object> rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region<String, Object> region = rf.create(PEOPLE_REGION_NAME);
rf.create(PEOPLE_REGION_NAME);
}

private void createClientCache(final String host, final int port) {
// Connect using the GemFire locator and create a Caching_Proxy cache
ClientCache clientCache =
new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();

clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
}

/**
* InterOps Test between REST-client, Peer Cache Client and Client Cache
*/
@Test
public void testInterOpsWithReplicatedRegion() throws Exception {
final Host host = Host.getHost(0);
VM locator = host.getVM(0);
VM manager = host.getVM(1);
VM server = host.getVM(2);
VM client = host.getVM(3);
VM locator = VM.getVM(0);
VM manager = VM.getVM(1);
VM server = VM.getVM(2);
VM client = VM.getVM(3);

// start locator
final String hostName = NetworkUtils.getServerHostName();
Expand All @@ -617,25 +642,23 @@ public void testInterOpsWithReplicatedRegion() throws Exception {
String locators = hostName + "[" + locatorPort + "]";

// start manager (peer cache)
manager.invoke(() -> startManager(/* groups */null, locators, new String[] {REGION_NAME},
CacheServer.DEFAULT_LOAD_PROBE));
manager.invoke(() -> startManager(locators, new String[] {REGION_NAME}));

// start startCacheServer With RestService enabled
final String serverHostName = server.getHost().getHostName();
String restEndpoint =
(String) server.invoke(() -> startBridgeServerWithRestService(serverHostName, null,
locators, new String[] {REGION_NAME}, CacheServer.DEFAULT_LOAD_PROBE));
String restEndpoint = server.invoke(() -> startBridgeServerWithRestService(serverHostName,
locators, new String[] {REGION_NAME}));

// create a client cache
client.invoke(() -> createClientCache(hostName, locatorPort));

// create region in Manager, peer cache and Client cache nodes
manager.invoke(() -> createRegion());
server.invoke(() -> createRegion());
client.invoke(() -> createRegionInClientCache());
manager.invoke(this::createRegion);
server.invoke(this::createRegion);
client.invoke(this::createRegionInClientCache);

// do some person puts from clientcache
client.invoke(() -> doPutsInClientCache());
client.invoke(this::doPutsInClientCache);

// TEST: fetch all available REST endpoints
fetchRestServerEndpoints(restEndpoint);
Expand All @@ -646,52 +669,9 @@ public void testInterOpsWithReplicatedRegion() throws Exception {
// update Data using REST APIs
doUpdatesUsingRestApis(restEndpoint);

client.invoke(() -> verifyUpdatesInClientCache());
client.invoke(this::verifyUpdatesInClientCache);

// Querying
doQueryOpsUsingRestApis(restEndpoint);
}

private void createClientCache(final String host, final int port) {
// Connect using the GemFire locator and create a Caching_Proxy cache
ClientCache clientCache =
new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();

clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
}

private int startManager(final String[] groups, final String locators, final String[] regions,
final ServerLoadProbe probe) throws IOException {
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, locators);

props.setProperty(JMX_MANAGER, "true");
props.setProperty(JMX_MANAGER_START, "true");
props.setProperty(JMX_MANAGER_PORT, "0");

final int httpPort = AvailablePortHelper.getRandomAvailableTCPPort();
// Set REST service related configuration
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));

DistributedSystem ds = getSystem(props);
Cache cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();

factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
CacheServer server = cache.addCacheServer();
server.setPort(0);
server.setGroups(groups);
server.setLoadProbe(probe);
server.start();

return server.getPort();
}
}

0 comments on commit 1b66d88

Please sign in to comment.