Skip to content

Commit

Permalink
Fix concurrency issue with string generation (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Sep 11, 2024
1 parent db1cc4a commit 897f1a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
5 changes: 5 additions & 0 deletions docs/content/v1.0.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ menu:
docs:
weight: 100
---
sectionStart
### v.1.0.25
Fix concurrency issue with string generation

sectionEnd

sectionStart
### v.1.0.24
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.0.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
### v.1.0.25
Fix concurrency issue with string generation

sectionEnd

sectionStart
### v.1.0.24
Deprecate `ElementJsonSubTypesObjectPropertyGenerator`, `PropertyJsonSubTypesObjectPropertyGenerator` in `fixture-monkey-jackson` module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.navercorp.fixturemonkey.api.arbitrary;

import static com.navercorp.fixturemonkey.api.jqwik.ArbitraryUtils.newThreadSafeArbitrary;
import static java.util.Arrays.asList;

import java.util.ArrayList;
Expand Down Expand Up @@ -71,10 +72,16 @@ public RandomGenerator<String> generator(int genSize) {
randomCharacterGenerator(),
minLength, maxLength(), maxUniqueChars,
genSize, lengthDistribution,
characterArbitrary
newThreadSafeArbitrary(characterArbitrary)
);
}

// Removing a StoreRepository dependency, it is not useful without Jqwik engine.
@Override
public RandomGenerator<String> generator(int genSize, boolean withEdgeCases) {
return this.generator(genSize);
}

private int maxLength() {
return RandomGenerators.collectionMaxSize(minLength, maxLength);
}
Expand Down Expand Up @@ -270,7 +277,6 @@ public int hashCode() {
return HashCodeSupport.hash(characterArbitrary, minLength, maxLength, repeatChars, filter, lengthDistribution);
}


public MonkeyStringArbitrary filterCharacter(Predicate<Character> predicate) {
this.filter = this.filter.and(predicate);
return this;
Expand All @@ -288,7 +294,6 @@ private RandomGenerator<Character> randomCharacterGenerator() {

private Arbitrary<Character> effectiveCharacterArbitrary() {
Arbitrary<Character> characterArbitrary = this.characterArbitrary;
return characterArbitrary.filter(this.filter);
return newThreadSafeArbitrary(characterArbitrary.filter(this.filter));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,30 @@ public static <T> CombinableArbitrary<T> toCombinableArbitrary(Arbitrary<T> arbi
return CombinableArbitrary.from(LazyArbitrary.lazy(
() -> {
if (arbitrary != null) {
return new Arbitrary<T>() {

@Override
public RandomGenerator<T> generator(int genSize) {
return arbitrary.generator(genSize);
}

// Removing a StoreRepository dependency, it is not useful without Jqwik engine.
@Override
public RandomGenerator<T> generator(int genSize, boolean withEdgeCases) {
return arbitrary.generator(genSize);
}

@Override
public EdgeCases<T> edgeCases(int maxEdgeCases) {
return arbitrary.edgeCases(maxEdgeCases);
}
}.sample();
return newThreadSafeArbitrary(arbitrary).sample();
}
return null;
}
));
}

public static <T> Arbitrary<T> newThreadSafeArbitrary(Arbitrary<T> delegate) {
return new Arbitrary<T>() {
@Override
public RandomGenerator<T> generator(int genSize) {
return delegate.generator(genSize);
}

// Removing a StoreRepository dependency, it is not useful without Jqwik engine.
@Override
public RandomGenerator<T> generator(int genSize, boolean withEdgeCases) {
return delegate.generator(genSize);
}

@Override
public EdgeCases<T> edgeCases(int maxEdgeCases) {
return delegate.edgeCases(maxEdgeCases);
}
};
}
}

0 comments on commit 897f1a9

Please sign in to comment.