Skip to content

Make the graphql-java Asserts truly lazy and hence more efficient#1913

Merged
bbakerman merged 5 commits into
masterfrom
klee97-lazyAssert
May 21, 2020
Merged

Make the graphql-java Asserts truly lazy and hence more efficient#1913
bbakerman merged 5 commits into
masterfrom
klee97-lazyAssert

Conversation

@bbakerman

@bbakerman bbakerman commented May 21, 2020

Copy link
Copy Markdown
Member

This means all asserts will be encouraged to be efficient by default.

It not longer possible to write an accidental slow one even if you do

assertTrue(b, String.format("%s", someExpensiveMethod())

because it wont compile.

it must now be

assertTrue(b, () -> String.format("%s", someExpensiveMethod())

I have commented on the actually changed files that matter.

This is technically not a breaking API change because it was marked as @internal. However its likely people have used it - well that's what @internal is there to warn people about. Soz but we reserve the right with a reason nad this is one of those reasons.

See #1876 for the original problem - this takes it much further

Katrina Lee and others added 3 commits April 22, 2020 16:20
It takes it much further and makes them ALL lazy in their message retrieval and encourages efficient asserts
by not providing the string.format rope with which to hang yourself.

We now require that a supplier be provided to asserts that want messages to be thrown
@bbakerman bbakerman added this to the 15.0 milestone May 21, 2020
@@ -1,25 +1,26 @@
package graphql;

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.

This is the KEY file changed and its test.

The others are all knock on effects

return;
}
throw new AssertException("condition expected to be false");
}

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.

The above was missing but present for assertTrue so I made it

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.

assertShouldNeverHappen can be as slow as it likes - its ALWAYS going to assert.

I mean we could make it a supplier based on consistency but....I thought its ok to leave it

@andimarek andimarek left a comment

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.

What about assertShouldNeverHappen?

@bbakerman bbakerman merged commit 2acb557 into master May 21, 2020
@andimarek andimarek deleted the klee97-lazyAssert branch June 5, 2020 10:44
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.

2 participants