-
Notifications
You must be signed in to change notification settings - Fork 22
Catch run-time and compile-time server exceptions #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1850a9e
Catch run-time and compile-time server exceptions
jeffreylovitz b0ec1e2
Address PR comments
jeffreylovitz 85cc0dc
Fix overly-broad catch logic
jeffreylovitz 7f54c56
fixed design - connection should stay open on an exception
c14484e
moved exception testing to different file. added context connection t…
c61a5eb
refactor - rename from error to exception. added JDoc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/com/redislabs/redisgraph/exceptions/JRedisGraphCompileTimeException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.redislabs.redisgraph.exceptions; | ||
|
|
||
| import redis.clients.jedis.exceptions.JedisDataException; | ||
|
|
||
| /** | ||
| * RedisGraph query syntax evaluation exception. An instance of JRedisGraphRunTimeException is thrown when RedisGraph | ||
| * encounters an error during query syntax evaluation. | ||
| */ | ||
| public class JRedisGraphCompileTimeException extends JedisDataException { | ||
| public JRedisGraphCompileTimeException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public JRedisGraphCompileTimeException(Throwable cause) { | ||
| super(cause); | ||
| } | ||
|
|
||
| public JRedisGraphCompileTimeException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/redislabs/redisgraph/exceptions/JRedisGraphRunTimeException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.redislabs.redisgraph.exceptions; | ||
|
|
||
| import redis.clients.jedis.exceptions.JedisDataException; | ||
|
|
||
| /** | ||
| * RedisGraph runtime exception. An instance of JRedisGraphRunTimeException is thrown when RedisGraph | ||
| * encounters a runtime error during query execution. | ||
| */ | ||
| public class JRedisGraphRunTimeException extends JedisDataException { | ||
| public JRedisGraphRunTimeException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public JRedisGraphRunTimeException(Throwable cause) { | ||
| super(cause); | ||
| } | ||
|
|
||
| public JRedisGraphRunTimeException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package com.redislabs.redisgraph.exceptions; | ||
|
|
||
| import com.redislabs.redisgraph.RedisGraphContext; | ||
| import com.redislabs.redisgraph.RedisGraphContextGenerator; | ||
| import com.redislabs.redisgraph.impl.api.RedisGraph; | ||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.ExpectedException; | ||
|
|
||
|
|
||
| public class JRedisGraphErrorTest { | ||
|
|
||
| private RedisGraphContextGenerator api; | ||
|
|
||
| @Before | ||
| public void createApi(){ | ||
| api = new RedisGraph(); | ||
| Assert.assertNotNull(api.query("social", "CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})")); | ||
| } | ||
| @After | ||
| public void deleteGraph() { | ||
|
|
||
| api.deleteGraph("social"); | ||
| api.close(); | ||
| } | ||
|
|
||
| @Rule | ||
| public ExpectedException exceptionRule = ExpectedException.none(); | ||
|
|
||
| @Test | ||
| public void testSyntaxErrorReporting() { | ||
| exceptionRule.expect(JRedisGraphCompileTimeException.class); | ||
| exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); | ||
|
|
||
| // Issue a query that causes a compile-time error | ||
| api.query("social", "RETURN toUpper(5)"); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testRuntimeErrorReporting() { | ||
| exceptionRule.expect(JRedisGraphRunTimeException.class); | ||
| exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); | ||
|
|
||
| // Issue a query that causes a run-time error | ||
| api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExceptionFlow() { | ||
|
|
||
| try { | ||
| // Issue a query that causes a compile-time error | ||
| api.query("social", "RETURN toUpper(5)"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); | ||
| Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); | ||
| } | ||
|
|
||
| // On general api usage, user should get a new connection | ||
|
|
||
| try { | ||
| // Issue a query that causes a compile-time error | ||
| api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); | ||
| Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testContextSyntaxErrorReporting() { | ||
| exceptionRule.expect(JRedisGraphCompileTimeException.class); | ||
| exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); | ||
| RedisGraphContext c = api.getContext(); | ||
|
|
||
| // Issue a query that causes a compile-time error | ||
| c.query("social", "RETURN toUpper(5)"); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testContextRuntimeErrorReporting() { | ||
| exceptionRule.expect(JRedisGraphRunTimeException.class); | ||
| exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); | ||
|
|
||
| RedisGraphContext c = api.getContext(); | ||
| // Issue a query that causes a run-time error | ||
| c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testContextExceptionFlow() { | ||
|
|
||
| RedisGraphContext c = api.getContext(); | ||
| try { | ||
| // Issue a query that causes a compile-time error | ||
| c.query("social", "RETURN toUpper(5)"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); | ||
| Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); | ||
| } | ||
|
|
||
| // On contexted api usage, connection should stay open | ||
|
|
||
| try { | ||
| // Issue a query that causes a compile-time error | ||
| c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); | ||
| } | ||
| catch (Exception e) { | ||
| Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); | ||
| Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); | ||
| } | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
few questions: