Skip to content

Commit

Permalink
Add new failing tests to help investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 4, 2023
1 parent 9d2bccc commit eb85a33
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.fasterxml.jackson.failing;

import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.core.*;

// 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(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,30 @@
package com.fasterxml.jackson.failing;

import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.core.*;

// 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(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 eb85a33

Please sign in to comment.