-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GEODE-9602: QueryObserver improvements. #6874
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package org.apache.geode.cache.query.internal; | ||
|
||
import static org.apache.geode.cache.Region.SEPARATOR; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
@@ -60,10 +61,12 @@ public class QueryTraceJUnitTest { | |
@Before | ||
public void setUp() throws Exception { | ||
CacheUtils.startCache(); | ||
DefaultQuery.testHook = new BeforeQueryExecutionHook(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
DefaultQuery.testHook = null; | ||
CacheUtils.closeCache(); | ||
} | ||
|
||
|
@@ -104,7 +107,11 @@ public void testTraceOnPartitionedRegionWithTracePrefix() throws Exception { | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -141,7 +148,11 @@ public void testTraceOnLocalRegionWithTracePrefix() throws Exception { | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -183,7 +194,11 @@ public void testNegTraceOnPartitionedRegionWithTracePrefix() throws Exception { | |
assertFalse(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertFalse(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should not have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isNotInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -223,7 +238,11 @@ public void testNegTraceOnLocalRegionWithTracePrefix() throws Exception { | |
assertFalse(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertFalse(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should not have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isNotInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -262,7 +281,11 @@ public void testTraceOnPartitionedRegionWithTracePrefixNoComments() throws Excep | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -296,7 +319,11 @@ public void testTraceOnLocalRegionWithTracePrefixNoComments() throws Exception { | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -331,7 +358,11 @@ public void testTraceOnPartitionedRegionWithSmallTracePrefixNoComments() throws | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -366,7 +397,11 @@ public void testTraceOnLocalRegionWithSmallTracePrefixNoComments() throws Except | |
assertTrue(((DefaultQuery) query).isTraced()); | ||
|
||
SelectResults results = (SelectResults) query.execute(); | ||
assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests seem awfully repetitive. Is there a reason to check the test hook in every test? From my perspective it seems like a waste of CPU. Just my opinion though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the way to check that the |
||
// The IndexTrackingObserver should have been set | ||
BeforeQueryExecutionHook hook = (BeforeQueryExecutionHook) DefaultQuery.testHook; | ||
assertThat(hook.getObserver()).isInstanceOf(IndexTrackingQueryObserver.class); | ||
|
||
// The query should return all elements in region. | ||
assertEquals(region.size(), results.size()); | ||
QueryObserverHolder.reset(); | ||
|
@@ -438,4 +473,21 @@ public void testQueryFailLocalRegionWithSmallTracePrefixNoSpace() throws Excepti | |
} | ||
} | ||
|
||
private class BeforeQueryExecutionHook implements DefaultQuery.TestHook { | ||
private QueryObserver observer = null; | ||
|
||
@Override | ||
public void doTestHook(final SPOTS spot, final DefaultQuery _ignored, | ||
final ExecutionContext executionContext) { | ||
switch (spot) { | ||
case BEFORE_QUERY_EXECUTION: | ||
observer = executionContext.getObserver(); | ||
break; | ||
} | ||
} | ||
|
||
public QueryObserver getObserver() { | ||
return observer; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to have been accidentally removed.