Skip to content

GEODE-3955: Add AEQ and Gateway Sender information to 'describe region' output.#1099

Closed
PurelyApplied wants to merge 11 commits into
apache:developfrom
PurelyApplied:geode-3955
Closed

GEODE-3955: Add AEQ and Gateway Sender information to 'describe region' output.#1099
PurelyApplied wants to merge 11 commits into
apache:developfrom
PurelyApplied:geode-3955

Conversation

@PurelyApplied

@PurelyApplied PurelyApplied commented Nov 29, 2017

Copy link
Copy Markdown
Member

I feel like the non-trivial refactoring deserves its own commit, if only for ease of review in this pull request.

My inexperience with Mockito is showing through and I got a little carried away in the RegionDescriptionJUnitTest. I don't know if the spy on its consumption in DescribeRegionCommand is 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 build run 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.

* 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import


import java.io.File;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import


import org.apache.commons.io.FileUtils;

import org.apache.geode.management.DistributedSystemMXBean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've sworn I pushed the buttons! I have become my own worst enemy.



if (partitionAttributes != null)
if (partitionAttributes != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+! Excellent refactoring!

}

@SuppressWarnings("deprecation")
private static void configureServers(MemberVM server1, MemberVM server2) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use commandResult.getTableContent instead of this private method.

.getJSONObject("__sections__-0").getJSONObject("__tables__-0").getJSONObject("content");
}

private JSONObject getMemberSpecificAttributeJson(CommandResult commandResult) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use commandResult.getTableContent

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jinmeiliao

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these commonMap.put's to group with the ones above - or did you intend for them to be put into the comparisonMap?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally meant them to be the other map. Good catch.

}

@Test
public void findCommonRemovesDisagreeingKeys() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better name might be "findCommonRemovesKeysWithDisagreeingValues"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure would be!


public static final String regionName = "mockRegion1";

private static final DescribeRegionCommand command = spy(DescribeRegionCommand.class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a DUnit or an Acceptance test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong, but I had thought that line was drawn between DUnit tests using LocatorServerStartupRule and AcceptanceTests using GfshRule.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why do we need to change to this? if need to be changed, why this complicated number? why not 2L?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be using LogWrapper - isn't that only for immediate gfsh use? Rather LogService.getLogger().

PurelyApplied added a commit that referenced this pull request Dec 6, 2017
…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.
@PurelyApplied PurelyApplied deleted the geode-3955 branch December 6, 2017 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants