GEODE-3955: Add AEQ and Gateway Sender information to 'describe region' output.#1099
GEODE-3955: Add AEQ and Gateway Sender information to 'describe region' output.#1099PurelyApplied wants to merge 11 commits into
Conversation
* Cleanup of DescribeRegionCommand for better readability and testability. * Flattened unnecessarily-nested logic blocks * Removed dead class fields from RegionDescription, RegionAttributesDefault * GetRegionDescriptionFunction implements Function instead of extending deprecated FunctionAdapter * Added waitTilGatewaySendersAreReady to MemberVM, MemberStarterRule
…n' output. * Add DUnit test coverage for 'describe region' command * Add JUnit test coverage for RegionDescription class
|
|
||
| package org.apache.geode.test.dunit.rules; | ||
|
|
||
| import static org.awaitility.Awaitility.await; |
|
|
||
| import java.io.File; | ||
| import java.util.Arrays; | ||
| import java.util.concurrent.TimeUnit; |
|
|
||
| import org.apache.commons.io.FileUtils; | ||
|
|
||
| import org.apache.geode.management.DistributedSystemMXBean; |
There was a problem hiding this comment.
I could've sworn I pushed the buttons! I have become my own worst enemy.
|
|
||
|
|
||
| if (partitionAttributes != null) | ||
| if (partitionAttributes != null) { |
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| private static void configureServers(MemberVM server1, MemberVM server2) { |
There was a problem hiding this comment.
just for easy understanding of what this test is doing, we could probably get rid of this entire call. We are not describing any of the regions created in here, right?
There was a problem hiding this comment.
Sure could! Another instance of not being judicious in what I copy when pulling something from another class.
| props.setProperty(REMOTE_LOCATORS, "localhost[" + sending_locator.getPort() + "]"); | ||
| lsRule.startLocatorVM(2, props); | ||
|
|
||
| MemberVM server1 = lsRule.startServerVM(3, "group1", sending_locator.getPort()); |
There was a problem hiding this comment.
do we need to have grouping for our servers? if we are not asserting it, we don't need to do that.
| } | ||
|
|
||
| @Test | ||
| public void describeRegionWithGatewayAndAsyncEventQueue() throws Exception { |
There was a problem hiding this comment.
since we have only one tests here, let's put the system setup in this test. If any future tests needs to be added, it's up to them to put any common setup in a @before tag. This would make it easy to spot what the test is doing.
| } | ||
|
|
||
| private JSONObject getSharedAttributedJson(CommandResult commandResult) { | ||
| return commandResult.getContent().getInternalJsonObject().getJSONObject("__sections__-0") |
There was a problem hiding this comment.
use commandResult.getTableContent instead of this private method.
| .getJSONObject("__sections__-0").getJSONObject("__tables__-0").getJSONObject("content"); | ||
| } | ||
|
|
||
| private JSONObject getMemberSpecificAttributeJson(CommandResult commandResult) { |
There was a problem hiding this comment.
use commandResult.getTableContent
There was a problem hiding this comment.
I will add some logic to the CommandResult class to go digging into the structure, since it seems to belong to that more than this class. Unfortunately, I can't just use getTableContent because the structure here is significantly different than in other commands, notably that this commandResult has two __section__-x levels before the tables.
|
In your Junit test, looks like you are extending the test to what's done in the DescribeRegionCommand. Let's get together to pair on wring a unit test for the command only. |
| comparisonMap.put(partKeyShared, partValueShared); | ||
| comparisonMap.put(regKeyShared, regValueShared); | ||
| commonMap.put(evictionKeyB, evictionValueB); | ||
| commonMap.put(regKeyA, regValueB); |
There was a problem hiding this comment.
Move these commonMap.put's to group with the ones above - or did you intend for them to be put into the comparisonMap?
There was a problem hiding this comment.
Totally meant them to be the other map. Good catch.
| } | ||
|
|
||
| @Test | ||
| public void findCommonRemovesDisagreeingKeys() { |
There was a problem hiding this comment.
A better name might be "findCommonRemovesKeysWithDisagreeingValues"
|
|
||
| public static final String regionName = "mockRegion1"; | ||
|
|
||
| private static final DescribeRegionCommand command = spy(DescribeRegionCommand.class); |
There was a problem hiding this comment.
It's not necessary to spy this, just define "command = new DescribeRegionCommand()".
The spy is really only necessary if you're specifying some test action using "when()" or using "verify" to makesure specific calls are made.
There was a problem hiding this comment.
Thanks. Still learning the ropes when it comes to Mockito.
I've refactored these into its own class and extended the mocking around DescribeRegionCommand, since it's really not part of the RegionDescription testing anyway.
| import org.apache.geode.test.junit.categories.DistributedTest; | ||
| import org.apache.geode.test.junit.rules.GfshCommandRule; | ||
|
|
||
| @Category(DistributedTest.class) |
There was a problem hiding this comment.
Should this be a DUnit or an Acceptance test?
There was a problem hiding this comment.
I could be wrong, but I had thought that line was drawn between DUnit tests using LocatorServerStartupRule and AcceptanceTests using GfshRule.
There was a problem hiding this comment.
Right. I guess I wasn't very clear - what I meant was look at what is being tested. This seems to be an overall end-to-end test that might fit better as an Acceptance test.
There was a problem hiding this comment.
Oh, that makes more sense.
Especially since most of the test is done via gfsh.executeAndAssertThat, it should be a pretty simple thing to convert this into a GfshScript.of(...). The only thing I wouldn't know how to convert is the guards that wait until the async event queues and the gateway senders are live. I don't know that those checks could work in an AcceptanceTest, since that would belong to a separate process.
Other than the "sleep for a while" anti-pattern, I don't see how to safely guarantee that the AEQ and Gateway are live before proceeding.
…nJUnit to their own JUnit class. Expand and clean existing tests.
…re .add is called. Remove various 'this.' in .add() for consistency with rest of method.
| */ | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private static final long serialVersionUID = 336184564012988487L; |
There was a problem hiding this comment.
Just curious, why do we need to change to this? if need to be changed, why this complicated number? why not 2L?
There was a problem hiding this comment.
I believe it's just a convention. It's not mentioned in any of the Google Java Style Guide that we've adopted as our own.
It needs to be changed to correctly deserialize, but I think you're right -- it could be changed to any not-the-previous-value-1 and be valid.
Looking around online, there doesn't seem to be any consensus on increment vs rehash the value. The best I could find was that a big, long number catches the eye and reminds future developers of the importance of considering backwards incompatibility.
| LogWrapper.getInstance().info(t.getMessage(), t); | ||
| // Log any errors received. | ||
| resultList.stream().filter(Throwable.class::isInstance).map(Throwable.class::cast) | ||
| .forEach(t -> LogWrapper.getInstance().info(t.getMessage(), t)); |
There was a problem hiding this comment.
I don't think this should be using LogWrapper - isn't that only for immediate gfsh use? Rather LogService.getLogger().
…n' output. * Add DUnit test coverage for 'describe region' command * Add JUnit test coverage for RegionDescription class * Expansion and refactoring of touched classes. - This closes #1099.
I feel like the non-trivial refactoring deserves its own commit, if only for ease of review in this pull request.
My inexperience with
Mockitois showing through and I got a little carried away in theRegionDescriptionJUnitTest. I don't know if thespyon its consumption inDescribeRegionCommandis beyond the scope of a reasonable JUnit and/or if we have (or should have) proper coverage of that in wider-scope tests. I don't really like how I dug into the command output JSON. So on the one hand, I don't really like those tests and could see them getting deleted. But on the other hand, it is more test coverage in the cheap JUnit category. Thoughts?Thank you for submitting a contribution to Apache Geode.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
Has your PR been rebased against the latest commit within the target branch (typically
develop)?Is your initial contribution a single, squashed commit?
Does
gradlew buildrun cleanly?Have you written or updated unit tests to verify your changes?
If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.