@Before public final void setUpLocatorLauncherTest() throws Exception { final int port = AvailablePortHelper.getRandomAvailableTCPPort(); System.setProperty( DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(port)); this.locatorPort = port; }
// Executes the query on the server with the RM and QM configured private void doCriticalMemoryHitTestOnServer( final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception { // create region on the server final Host host = Host.getHost(0); final VM server = host.getVM(0); final VM client = host.getVM(1); final int numObjects = 200; try { final int port = AvailablePortHelper.getRandomAvailableTCPPort(); startCacheServer( server, port, criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0); // startPeerClient(client, server, port, regionName); populateData(server, regionName, numObjects); doTestCriticalHeapAndQueryTimeout( server, server, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold); // Pause for a second and then let's recover try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } // Recover from critical heap if (hitCriticalThreshold) { vmRecoversFromCriticalHeap(server); } // Check to see if query execution is ok under "normal" or "healthy" conditions server.invoke( new CacheSerializableRunnable("Executing query when system is 'Normal'") { public void run2() { try { QueryService qs = getCache().getQueryService(); Query query = qs.newQuery("Select * From /" + regionName); SelectResults results = (SelectResults) query.execute(); assertEquals(numObjects, results.size()); } catch (QueryInvocationTargetException e) { assertFalse(true); } catch (NameResolutionException e) { assertFalse(true); } catch (TypeMismatchException e) { assertFalse(true); } catch (FunctionDomainException e) { assertFalse(true); } } }); // Execute a critical heap event/ query timeout test again doTestCriticalHeapAndQueryTimeout( server, server, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold); // Recover from critical heap if (hitCriticalThreshold) { vmRecoversFromCriticalHeap(server); } } finally { stopServer(server); } }
// tests low memory hit while gathering partition region results private void doCriticalMemoryHitDuringGatherTestWithMultipleServers( final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception { // create region on the server final Host host = Host.getHost(0); final VM server1 = host.getVM(0); final VM server2 = host.getVM(1); final VM client = host.getVM(2); final int numObjects = 200; try { final int[] port = AvailablePortHelper.getRandomAvailableTCPPorts(2); startCacheServer( server1, port[0], criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0); startCacheServer(server2, port[1], criticalThreshold, true, -1, regionName, createPR, 0); startClient(client, server1, port[0], regionName); populateData(server2, regionName, numObjects); createCancelDuringGatherTestHook(server1); client.invoke( new SerializableCallable("executing query to be canceled by gather") { public Object call() { QueryService qs = null; try { qs = getCache().getQueryService(); Query query = qs.newQuery("Select * From /" + regionName); query.execute(); } catch (ServerOperationException soe) { if (soe.getRootCause() instanceof QueryException) { QueryException e = (QueryException) soe.getRootCause(); if (!isExceptionDueToLowMemory(e, CRITICAL_HEAP_USED)) { throw new CacheException(soe) {}; } else { return 0; } } } catch (Exception e) { throw new CacheException(e) {}; } // assertTrue(((CancelDuringGatherHook)DefaultQuery.testHook).triggeredOOME); throw new CacheException("should have hit low memory") {}; } }); verifyRejectedObjects( server1, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold); // Pause for a second and then let's recover try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } // Recover from critical heap if (hitCriticalThreshold) { vmRecoversFromCriticalHeap(server1); } // Check to see if query execution is ok under "normal" or "healthy" conditions client.invoke( new CacheSerializableRunnable("Executing query when system is 'Normal'") { public void run2() { try { QueryService qs = getCache().getQueryService(); Query query = qs.newQuery("Select * From /" + regionName); SelectResults results = (SelectResults) query.execute(); assertEquals(numObjects, results.size()); } catch (QueryInvocationTargetException e) { assertFalse(true); } catch (NameResolutionException e) { assertFalse(true); } catch (TypeMismatchException e) { assertFalse(true); } catch (FunctionDomainException e) { assertFalse(true); } } }); // Recover from critical heap if (hitCriticalThreshold) { vmRecoversFromCriticalHeap(server1); } } finally { stopServer(server1); stopServer(server2); } }
// test to verify what happens during index creation if memory threshold is hit private void doCriticalMemoryHitWithIndexTest( final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold, final String indexType) throws Exception { // create region on the server final Host host = Host.getHost(0); final VM server1 = host.getVM(0); final VM server2 = host.getVM(2); final VM client = host.getVM(1); final int numObjects = 200; try { final int[] port = AvailablePortHelper.getRandomAvailableTCPPorts(2); startCacheServer( server1, port[0], criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0); startCacheServer(server2, port[1], criticalThreshold, true, -1, regionName, createPR, 0); startClient(client, server1, port[0], regionName); populateData(server1, regionName, numObjects); createCancelDuringGatherTestHook(server1); server1.invoke( new SerializableCallable("create index") { public Object call() { QueryService qs = null; try { qs = getCache().getQueryService(); Index index = null; if (indexType.equals("compact")) { index = qs.createIndex("newIndex", "ID", "/" + regionName); } else if (indexType.equals("hash")) { index = qs.createHashIndex("newIndex", "ID", "/" + regionName); } assertNotNull(index); assertTrue(((CancelDuringGatherHook) DefaultQuery.testHook).triggeredOOME); if (hitCriticalThreshold && !disabledQueryMonitorForLowMem) { throw new CacheException("Should have hit low memory") {}; } assertEquals(1, qs.getIndexes().size()); } catch (Exception e) { if (e instanceof IndexInvalidException) { if (!hitCriticalThreshold || disabledQueryMonitorForLowMem) { throw new CacheException("Should not have run into low memory exception") {}; } } else { throw new CacheException(e) {}; } } return 0; } }); } finally { stopServer(server1); stopServer(server2); } }