Skip to content

Commit

Permalink
Fix OOM when annotated size without max
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Mar 19, 2022
1 parent 3f0daf9 commit 21d5371
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.navercorp.fixturemonkey.arbitrary;

import static com.navercorp.fixturemonkey.Constants.DEFAULT_ELEMENT_MAX_SIZE;
import static com.navercorp.fixturemonkey.Constants.HEAD_NAME;
import static com.navercorp.fixturemonkey.Constants.NO_OR_ALL_INDEX_INTEGER_VALUE;

Expand Down Expand Up @@ -114,7 +115,11 @@ public void initializeElementSize() {
Size size = type.getAnnotation(Size.class);
if (size != null) {
min = size.min();
max = size.max();
if (size.max() != Integer.MAX_VALUE) { // not initialized for preventing OOM
max = size.max();
} else {
max = min + DEFAULT_ELEMENT_MAX_SIZE;
}
}

NotEmpty notEmpty = type.getAnnotation(NotEmpty.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.navercorp.fixturemonkey.test;

import static com.navercorp.fixturemonkey.Constants.DEFAULT_ELEMENT_MAX_SIZE;
import static com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.SUT;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.BDDAssertions.then;
Expand Down Expand Up @@ -52,6 +53,7 @@
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntArray;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntWithAnnotation;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntegerArray;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntegerListAnnotatedBySizeWithoutMax;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntegerListWithNotEmpty;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntegerOptional;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.IntegerSet;
Expand Down Expand Up @@ -1337,4 +1339,10 @@ void giveMeQueue(@ForAll StringQueue expected) {
void giveMeNestedQueue(@ForAll NestedStringQueue expected) {
then(expected.getValues()).isNotNull();
}

@Property
@Domain(FixtureMonkeyTestSpecs.class)
void giveMeListAnnotatedBySizeWithoutMax(@ForAll IntegerListAnnotatedBySizeWithoutMax actual) {
then(actual.getValues()).hasSizeBetween(1, 1 + DEFAULT_ELEMENT_MAX_SIZE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;

import net.jqwik.api.Arbitrary;
import net.jqwik.api.Provide;
Expand Down Expand Up @@ -66,6 +67,7 @@ class FixtureMonkeyTestSpecs extends AbstractDomainContextBase {
registerArbitrary(ListWithAnnotation.class, listWithAnnotation());
registerArbitrary(StringQueue.class, stringQueue());
registerArbitrary(NestedStringQueue.class, nestedStringQueue());
registerArbitrary(IntegerListAnnotatedBySizeWithoutMax.class, integerListAnnotatedBySizeWithoutMax());
}

@Provide
Expand Down Expand Up @@ -285,6 +287,17 @@ Arbitrary<NestedStringQueue> nestedStringQueue() {
return SUT.giveMeArbitrary(NestedStringQueue.class);
}

@Data
public static class IntegerListAnnotatedBySizeWithoutMax {
@Size(min = 1)
private List<Integer> values;
}

@Provide
Arbitrary<IntegerListAnnotatedBySizeWithoutMax> integerListAnnotatedBySizeWithoutMax() {
return SUT.giveMeArbitrary(IntegerListAnnotatedBySizeWithoutMax.class);
}

public static class DefaultArbitraryGroup {
public DefaultArbitraryGroup() {
}
Expand Down

0 comments on commit 21d5371

Please sign in to comment.