use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class PdxStringQueryJUnitTest method testQueriesWithRangeIndexWithREUpdateInProgress.
@Test
public void testQueriesWithRangeIndexWithREUpdateInProgress() throws Exception {
Index index = qs.createIndex("index2", "p.secId", "/exampleRegion p, p.positions.values");
assertTrue(index instanceof RangeIndex);
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 111);
pf.writeString("secId", "IBM");
pf.writeString("status", "active");
HashMap positions = new HashMap();
positions.put("price", "50");
positions.put("price", "60");
pf.writeObject("positions", positions);
PdxInstance pi = pf.create();
r.put("IBM", pi);
positions = new HashMap();
positions.put("price", "100");
positions.put("price", "120");
r.put("YHOO", new TestObject(222, "YHOO", positions, "inactive"));
pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 333);
pf.writeString("secId", "GOOGL");
pf.writeString("status", "active");
positions = new HashMap();
positions.put("price", "130");
positions.put("price", "150");
pf.writeObject("positions", positions);
pi = pf.create();
positions = new HashMap();
positions.put("price", "200");
positions.put("price", "220");
r.put("VMW", new TestObject(111, "VMW", positions, "inactive"));
r.put("GOOGL", pi);
makeREUpdateInProgress();
Map map = ((RangeIndex) index).getValueToEntriesMap();
for (Object key : map.keySet()) {
assertTrue(key instanceof PdxString);
}
DefaultQuery.setPdxReadSerialized(true);
executeQueriesValidateResults(INDEX_TYPE_RANGE);
qs.removeIndex(index);
r.clear();
}
use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class PdxStringQueryJUnitTest method putPdxInstancesWithREUpdateInProgress.
public void putPdxInstancesWithREUpdateInProgress() throws Exception {
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 111);
pf.writeString("status", "active");
pf.writeString("secId", "IBM");
PdxInstance pi = pf.create();
r.put("IBM", pi);
pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 222);
pf.writeString("status", "inactive");
pf.writeString("secId", "YHOO");
pi = pf.create();
r.put("YHOO", pi);
pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 333);
pf.writeString("status", "active");
pf.writeString("secId", "GOOGL");
pi = pf.create();
r.put("GOOGL", pi);
pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 111);
pf.writeString("status", "inactive");
pf.writeString("secId", "VMW");
pi = pf.create();
r.put("VMW", pi);
makeREUpdateInProgress();
}
use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class SelectStarQueryDUnitTest method testSelectStarQueryForPdxAndNonPdxObjects.
@Test
public void testSelectStarQueryForPdxAndNonPdxObjects() throws Exception {
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM client = host.getVM(3);
// create servers and regions
// put domain objects
final int port1 = startReplicatedCacheServer(server1);
server1.invoke(new SerializableCallable("Set observer") {
@Override
public Object call() throws Exception {
oldObserver = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
return null;
}
});
// create client
client.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory();
cf.addPoolServer(getServerHostName(server1.getHost()), port1);
ClientCache cache = getClientCache(cf);
cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
return null;
}
});
// Add some serialized PortfolioPdx objects
client.invoke(new SerializableCallable("Put objects") {
@Override
public Object call() throws Exception {
Region r1 = getRootRegion(regName);
for (int i = 10; i < 20; i++) {
r1.put("key-" + i, new PortfolioPdx(i));
}
return null;
}
});
// query remotely from client
client.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
getLogWriter().info("Querying remotely from client");
QueryService localQS = null;
QueryService remoteQS = null;
try {
localQS = ((ClientCache) getCache()).getLocalQueryService();
remoteQS = ((ClientCache) getCache()).getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
SelectResults[][] sr = new SelectResults[1][2];
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) localQS.newQuery(queries[i]).execute();
sr[0][0] = res;
res = (SelectResults) remoteQS.newQuery(queries[i]).execute();
sr[0][1] = res;
CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx or PortfolioPdx and not " + obj.getClass());
}
}
} else if (rs instanceof PortfolioPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
}
}
}
}
return null;
}
});
// verify if objects iterated by query are serialized
server1.invoke(new SerializableCallable("Get observer") {
@Override
public Object call() throws Exception {
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
assertTrue(observer instanceof QueryResultTrackingObserver);
QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
assertTrue(resultObserver.isObjectSerialized());
return null;
}
});
// verify if objects returned by local server query are not serialized
server1.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
QueryObserver observer = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
QueryService qs = null;
try {
qs = getCache().getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) qs.newQuery(queries[i]).execute();
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx or PortfolioPdx and not " + obj.getClass());
}
}
} else if (rs instanceof PortfolioPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
}
}
}
}
observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
assertTrue(observer instanceof QueryResultTrackingObserver);
QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
assertFalse(resultObserver.isObjectSerialized());
QueryObserverHolder.setInstance(oldObserver);
return null;
}
});
server1.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
cache.setReadSerialized(true);
QueryService qs = null;
try {
qs = getCache().getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) qs.newQuery(queries[i]).execute();
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else if (obj instanceof PdxInstance) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + obj.getClass());
}
}
} else if (rs instanceof PdxInstance || rs instanceof PortfolioPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + rs.getClass());
}
}
}
}
return null;
}
});
closeCache(client);
closeCache(server1);
}
use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class DataBrowserJSONValidationJUnitTest method testNestedPDXObject.
@Test
public void testNestedPDXObject() {
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeInt("ID", 111);
pf.writeString("status", "active");
pf.writeString("secId", "IBM");
PdxInstance pi = pf.create();
replicatedRegion.put("port", pi);
queryData(QUERY_1, "", 0);
}
use of org.apache.geode.pdx.PdxInstance in project geode by apache.
the class AbstractBaseController method updateSingleKey.
ResponseEntity<String> updateSingleKey(final String region, final String key, final String json, final String opValue) {
final JSONTypes jsonType = validateJsonAndFindType(json);
final UpdateOp op = UpdateOp.valueOf(opValue.toUpperCase());
String existingValue = null;
switch(op) {
case CAS:
PdxInstance existingPdxObj = casValue(region, key, json);
existingValue = convert(existingPdxObj);
break;
case REPLACE:
replaceValue(region, key, convert(json));
break;
case PUT:
default:
if (JSONTypes.JSON_ARRAY.equals(jsonType)) {
putValue(region, key, convertJsonArrayIntoPdxCollection(json));
// putValue(region, key, convertJsonIntoPdxCollection(json));
} else {
putValue(region, key, convert(json));
}
}
final HttpHeaders headers = new HttpHeaders();
headers.setLocation(toUri(region, key));
return new ResponseEntity<String>(existingValue, headers, (existingValue == null ? HttpStatus.OK : HttpStatus.CONFLICT));
}
Aggregations