Skip to content

Dirty Flag pattern #560 - #717

Merged
npathai merged 10 commits into
iluwatar:masterfrom
waisuan:master
May 16, 2018
Merged

npathai merged 10 commits into
iluwatar:masterfrom
waisuan:master

Conversation

@waisuan

@waisuan waisuan commented Feb 19, 2018 •

Copy link
Copy Markdown
Contributor
  • Implementation of the Dirty Flag pattern

@npathai npathai self-assigned this Feb 26, 2018
@npathai

npathai commented Feb 26, 2018

Copy link
Copy Markdown
Contributor

@iluwatar I will pick up this review.

@iluwatar

iluwatar commented Mar 4, 2018

Copy link
Copy Markdown
Owner

Ok @npathai
@waisuan the pull request has conflicts that need to be resolved

@waisuan

waisuan commented Mar 4, 2018

Copy link
Copy Markdown
Contributor Author

@iluwatar Done.

@waisuan

waisuan commented Mar 4, 2018

Copy link
Copy Markdown
Contributor Author

Seems to be a JUnit test failure:-

dummyCustomerApiTest() Time elapsed: 0.052 sec <<< FAILURE!
org.opentest4j.AssertionFailedError: Counter limit must be reached ==> expected: but was:
at com.iluwatar.throttling.B2BServiceTest.dummyCustomerApiTest(B2BServiceTest.java:46)

Doesn't seem to be related to my changes here.

@iluwatar

@iluwatar

Copy link
Copy Markdown
Owner

It is a known issue #643, still unresolved

@iluwatar

Copy link
Copy Markdown
Owner

@npathai please review the PR

@npathai

npathai commented Mar 17, 2018

Copy link
Copy Markdown
Contributor

@iluwatar Yes started. Will complete today

return data;
}

return null;

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 am not sure if DataFetcher should be returning null to indicate no change in data. Any other options for this?

* @return World instance
*/
public static World getInstance() {
if (world == null) {

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.

Suggestion: Just document a warning that this is not a thread safe way to implement Singleton. Refer to Singleton for more information.

*
* @return DataFetcher instance
*/
public static DataFetcher getInstance() {

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.

Question: I don't understand the intent to keep World and DataFetcher singleton here. Any particular reason you chose this way?


@BeforeEach
public void reset() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Field instance = DataFetcher.class.getDeclaredField("df");

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.

This singleton reset thing won't be needed if we avoid getInstance. Hence my question about Singletonness.

Comment thread dirty-flag/README.md
To avoid expensive re-acquisition of resources. The resources retain their identity, are kept in some
fast-access storage, and are re-used to avoid having to acquire them again.

![alt text](./etc/dirty-flag.png "Dirty Flag")

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.

The class diagram should be made with ObjectAid eclipse plugin. More about it in wiki

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@npathai

npathai commented Mar 17, 2018 •

Copy link
Copy Markdown
Contributor

@waisuan You have my review comments. Overall it looks great and easy to follow. 👍 There are a few points that I have highlighted though. Awaiting your response.

@npathai

npathai commented Apr 23, 2018

Copy link
Copy Markdown
Contributor

@waisuan Any updates?

@waisuan

waisuan commented May 2, 2018

Copy link
Copy Markdown
Contributor Author

@npathai Apologies for the delay here. Been swamped. I'll take a look at your comments tonight and begin working on them accordingly. Cheers!

@waisuan

waisuan commented May 12, 2018

Copy link
Copy Markdown
Contributor Author

@npathai -- Fixes are up. Could you take another peek? Thanks!

@npathai

npathai commented May 13, 2018

Copy link
Copy Markdown
Contributor

@waisuan 👍 Surely. I will do that tomorrow.

@npathai npathai left a comment

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.

There was one minor change, but lets merge this now and we can do that minor change later.

public void testIsDirty() {
DataFetcher df = new DataFetcher();
List<String> countries = df.fetch();
assertTrue(!countries.isEmpty());

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.

Use assertFalse() in place of assertTrue(!condition)

@npathai
npathai merged commit eddfe76 into iluwatar:master May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants