use of org.apache.geode.cache.query.data.PortfolioData in project geode by apache.
the class PRQueryRemoteNodeExceptionDUnitTest method testRemoteException.
@Test
public void testRemoteException() throws Exception {
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Querying with PR Local/Remote Exception test Started");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
setCacheInVMs(vm0, vm1);
List vmList = new LinkedList();
vmList.add(vm1);
vmList.add(vm0);
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Creating PR's across all VM0 , VM1");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreateLimitedBuckets(name, redundancy, numOfBuckets));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreateLimitedBuckets(name, redundancy, numOfBuckets));
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Successfully Created PR on VM0 , VM1");
// creating a local region on one of the JVM's
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Creating Local Region on VM0");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(localName, PortfolioData.class));
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Successfully Created Local Region on VM0");
// Generating portfolio object array to be populated across the PR's & Local
// Regions
final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
// Putting the data into the accessor node
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Inserting Portfolio data through the accessor node");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Successfully Inserted Portfolio data through the accessor node");
// Putting the same data in the local region created
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Inserting Portfolio data on local node VM0 for result Set Comparison");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(localName, portfolio, cnt, cntDest));
LogWriterUtils.getLogWriter().info("PRQueryRegionDestroyedDUnitTest#testPRWithLocalAndRemoteException: Successfully Inserted Portfolio data on local node VM0 for result Set Comparison");
vm0.invoke(new CacheSerializableRunnable(name) {
@Override
public void run2() throws CacheException {
boolean gotException = false;
Cache cache = PRQHelp.getCache();
class MyQueryObserver extends QueryObserverAdapter {
@Override
public void startQuery(Query query) {
// Replacing QueryObserver of previous test.
}
}
;
QueryObserverHolder.setInstance(new MyQueryObserver());
}
});
// Insert the test hooks on local and remote node.
// Test hook on remote node will throw CacheException while Test hook on local node will throw
// QueryException.
vm1.invoke(new CacheSerializableRunnable(name) {
@Override
public void run2() throws CacheException {
class MyQueryObserver extends IndexTrackingQueryObserver {
@Override
public void startQuery(Query query) {
throw new RuntimeException("For testing purpose only from remote node");
}
}
;
QueryObserverHolder.setInstance(new MyQueryObserver());
}
;
});
vm0.invoke(new CacheSerializableRunnable(name) {
@Override
public void run2() throws CacheException {
boolean gotException = false;
Cache cache = PRQHelp.getCache();
final DefaultQuery query = (DefaultQuery) cache.getQueryService().newQuery("Select * from /" + name);
try {
query.execute();
} catch (Exception ex) {
gotException = true;
if (ex.getMessage().contains("remote node")) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("PRQueryRemoteNodeExceptionDUnitTest: Test received Exception from remote node successfully.");
} else {
Assert.fail("PRQueryRemoteNodeExceptionDUnitTest: Test did not receive Exception as expected from remote node rather received", ex);
}
}
if (!gotException) {
fail("PRQueryRemoteNodeExceptionDUnitTest#testRemoteException: Test did not receive Exception as expected from remote node");
}
}
});
LogWriterUtils.getLogWriter().info("PRQueryRemoteNodeExceptionDUnitTest#testPRWithLocalAndRemoteException: Querying with PR Local/Remote Exception Test ENDED");
}
use of org.apache.geode.cache.query.data.PortfolioData in project geode by apache.
the class PRQueryDUnitTest method testPRDAckCreationAndQuerying.
/**
* This test <br>
* 1. Creates PR regions on 4 VMs (all datastores) with scope = D_ACK <br>
* 2. Creates a Local region on one of the VM's <br>
* 3. Puts in the same data both in PR region & the Local Region <br>
* 4. Queries the data both in local & PR <br>
* 5. Verfies the size ,type , contents of both the resultSets Obtained
*
* @throws Exception
*/
@Test
public void testPRDAckCreationAndQuerying() throws Exception {
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Querying PR Test with DACK Started*****");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
setCacheInVMs(vm0, vm1, vm2, vm3);
// Creating PR's on the participating VM's
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Creating PR's on VM0, VM1 , VM2 , VM3");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Successfully Created PR's on VM0, VM1 , VM2 , VM3");
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Creating Local region on VM0 to compare result Sets");
// creating a local region on one of the JVM's
vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(localName, PortfolioData.class));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Successfully Created Local Region on VM0");
// Generating portfolio object array to be populated across the PR's & Local
// Regions
final PortfolioData[] portfolio = createPortfolioData(cnt, totalDataSize);
// Putting the data into the PR's created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, i, stepSize));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, stepSize, (2 * stepSize)));
vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, (2 * stepSize), (3 * stepSize)));
vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, (3 * (stepSize)), totalDataSize));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Inserted Portfolio data across PR's");
// Putting the same data in the local region created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(localName, portfolio, i, totalDataSize));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : Inserted Portfolio data over Local Region on VM0");
// querying the VM for data
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRQueryAndCompareResults(name, localName));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQuerying : *Querying PR's with DACK Test ENDED*****");
}
use of org.apache.geode.cache.query.data.PortfolioData in project geode by apache.
the class PRQueryDUnitTest method testPRDAckCreationAndQueryingWithConstants.
/**
* This test <br>
* 1. Creates PR regions across with scope = DACK <br>
* 2. Creates a Local region on one of the VM's <br>
* 3. Puts in the same data both in PR region & the Local Region <br>
* 4. Queries the data both in local & PR using Query Constants like NULL , UNDEFINED , TRUE,
* FALSE<br>
* 5. Verfies the size ,type , contents of both the resultSets Obtained
*
* @throws Exception
*/
@Test
public void testPRDAckCreationAndQueryingWithConstants() throws Exception {
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Querying PR Test with DACK Started*****");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
setCacheInVMs(vm0, vm1, vm2, vm3);
// Creating PR's on the participating VM's
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Creating PR's on VM0, VM1 , VM2 , VM3");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, redundancy, PortfolioData.class));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Successfully Created PR's on VM0, VM1 , VM2 , VM3");
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Creating Local region on VM0 to compare result Sets");
// creating a local region on one of the JVM's
vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(localName, PortfolioData.class));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Successfully Created Local Region on VM0");
// Generating portfolio object array to be populated across the PR's & Local
// Regions
final PortfolioData[] portfolio = createPortfolioData(cnt, totalDataSize);
// Putting the data into the PR's created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, i, stepSize));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, stepSize, (2 * stepSize)));
vm2.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, (2 * stepSize), (3 * stepSize)));
vm3.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, (3 * (stepSize)), totalDataSize));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Inserted Portfolio data across PR's");
// Putting the same data in the local region created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(localName, portfolio, i, totalDataSize));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : Inserted Portfolio data over Local Region on VM0");
// querying the VM for data
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults(name, localName));
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testPRDAckCreationAndQueryingWithConstants : *Querying PR's with DACK Test ENDED*****");
}
use of org.apache.geode.cache.query.data.PortfolioData in project geode by apache.
the class PRQueryJUnitTest method testQueryOnSingleDataStore.
/**
* Tests the execution of query on a PartitionedRegion created on a single data store. <br>
* 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects in cache. 3. Fires
* queries on the data and verifies the result.
*
* @throws Exception
*/
@Test
public void testQueryOnSingleDataStore() throws Exception {
Region region = PartitionedRegionTestHelper.createPartitionedRegion(regionName, "100", 0);
PortfolioData[] portfolios = new PortfolioData[100];
for (int j = 0; j < 100; j++) {
portfolios[j] = new PortfolioData(j);
}
try {
populateData(region, portfolios);
String queryString = "ID < 5";
SelectResults resSet = region.query(queryString);
Assert.assertTrue(resSet.size() == 5);
queryString = "ID > 5 and ID <=15";
resSet = region.query(queryString);
Assert.assertTrue(resSet.size() == 10);
} finally {
region.close();
}
}
use of org.apache.geode.cache.query.data.PortfolioData in project geode by apache.
the class PRQueryNumThreadsJUnitTest method testQueryOnSingleDataStore.
/**
* Tests the execution of query on a PartitionedRegion created on a single data store. <br>
* 1. Creates a PR with redundancy=0 on a single VM. 2. Puts some test Objects in cache. 3. Fires
* queries on the data and verifies the result.
*
* @throws Exception
*/
@Test
public void testQueryOnSingleDataStore() throws Exception {
Region region = PartitionedRegionTestHelper.createPartitionedRegion(regionName, "100", 0);
PortfolioData[] portfolios = new PortfolioData[100];
for (int j = 0; j < 100; j++) {
portfolios[j] = new PortfolioData(j);
}
PRQueryProcessor.TEST_NUM_THREADS = 10;
try {
populateData(region, portfolios);
String queryString = "ID < 5";
SelectResults resSet = region.query(queryString);
Assert.assertTrue(resSet.size() == 5);
queryString = "ID > 5 and ID <=15";
resSet = region.query(queryString);
Assert.assertTrue(resSet.size() == 10);
} finally {
PRQueryProcessor.TEST_NUM_THREADS = 0;
region.close();
}
}
Aggregations