-
-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/test/java/tools/jackson/failing/PerfBigDecimalParser967.java
This file contains 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,38 @@ | ||
package tools.jackson.failing; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import tools.jackson.core.*; | ||
import tools.jackson.core.json.JsonFactory; | ||
|
||
// For [core#967] | ||
public class PerfBigDecimalParser967 | ||
{ | ||
private final JsonFactory JSON_F = new JsonFactory(); | ||
|
||
// For [core#967]: shouldn't take multiple seconds | ||
@Test(timeout = 35000) | ||
public void bigDecimalFromString() throws Exception { | ||
// Jackson's BigDecimalParser seems to be slower than JDK's; | ||
// won't fail if using latter. | ||
StringBuilder sb = new StringBuilder(900); | ||
for (int i = 0; i < 500; ++i) { | ||
sb.append('1'); | ||
} | ||
sb.append("1e10000000"); | ||
final String DOC = sb.toString(); | ||
|
||
try (JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), DOC)) { | ||
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken()); | ||
Assert.assertNotNull(p.getDecimalValue()); | ||
} | ||
} | ||
|
||
protected void assertToken(JsonToken expToken, JsonToken actToken) | ||
{ | ||
if (actToken != expToken) { | ||
Assert.fail("Expected token "+expToken+", current token "+actToken); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/tools/jackson/failing/PerfBigDecimalToInteger968.java
This file contains 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,31 @@ | ||
package tools.jackson.failing; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import tools.jackson.core.*; | ||
import tools.jackson.core.json.JsonFactory; | ||
|
||
// For [core#968]] | ||
public class PerfBigDecimalToInteger968 | ||
{ | ||
private final JsonFactory JSON_F = new JsonFactory(); | ||
|
||
// For [core#968]]: shouldn't take multiple seconds | ||
@Test(timeout = 3000) | ||
public void bigIntegerViaBigDecimal() throws Exception { | ||
final String DOC = "1e20000000"; | ||
|
||
try (JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), DOC)) { | ||
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken()); | ||
Assert.assertNotNull(p.getBigIntegerValue()); | ||
} | ||
} | ||
|
||
protected void assertToken(JsonToken expToken, JsonToken actToken) | ||
{ | ||
if (actToken != expToken) { | ||
Assert.fail("Expected token "+expToken+", current token "+actToken); | ||
} | ||
} | ||
} |