Skip to content

Commit

Permalink
Merge branch '2.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 1, 2023
2 parents d206b58 + 350dfd2 commit 384c805
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/tools/jackson/failing/PerfBigDecimalParser967.java
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);
}
}
}
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);
}
}
}

0 comments on commit 384c805

Please sign in to comment.