Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor build as private #111

Closed
wants to merge 3 commits into from

Conversation

seongahjo
Copy link
Contributor

@seongahjo seongahjo commented Jan 4, 2022

ArbitraryBuilder 인터페이스에서 jqwik의 Arbitrary 의존성을 제거하기 위해 build를 private으로 변경하여 클라이언트에게 노출하지 않습니다.

이런 결정을 한 이유는 다음과 같습니다.

  1. jqwik이 버전업될 때마다 breaking change가 생길 위험이 있다.
  2. Fixture Monkey에서 만들어진 Arbitrary는 apply, acceptIf 등의 복잡한 연산을 사용하는 경우 jqwik에서 정의한 연산을 의도대로 지원하기 어렵다.
  3. 사용자는 Arbitrary 인터페이스에서 극히 일부 메소드만 사용한다.
  4. Arbitrary 인터페이스 지원은 Fixture Monkey 기능 확장을 방해한다.

@@ -179,7 +180,8 @@ private ArbitraryBuilder(
return this;
}

public Arbitrary<T> build() {
@API(since = "0.4.0", status = Status.EXPERIMENTAL)
Arbitrary<T> build() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private 으로 하면 될거 같습니다.

Copy link
Contributor Author

@seongahjo seongahjo Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private으로 전환하면서 giveMeArbitrarybuild는 동일한 의도인 것 같아서 giveMeArbitrary도 제거했습니다.
autoparams 모듈에서도 Arbitrary가 아닌 ArbitraryBuilder를 반환하도록 수정했습니다.


@mhyeon-lee
jqwik 엔진을 사용해 테스트를 하려면 giveMeArbitrary가 필요하네요.
private으로 두지 않고 package-private으로 뒀을 때 문제가 있을까요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seongahjo @Provider 로 제공하는거 때문에 그런거죠?
그러고보니 package-private 이든 private 이든 바꾸면 @Provider 로 아예 사용 못하는거 아닌가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhyeon-lee
ArbitraryBuilder와 동일한 패키지에 존재하는 Fixture Monkey 인스턴스에서 package-private 인 build를 사용하여 Arbitrary를 public 메소드인 giveMeArbitrary 으로 노출하고 있기 때문에 사용할 수 있습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seongahjo
@Provider 에서 ArbitraryBuilder 로 조작을 한 Arbitrary 는 반환 못하는거 아닌가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhyeon-lee
넵 맞습니다.
지금 있는 테스트 중에서는 ArbitraryBuilder에서 Arbitrary를 생성해서 테스트하는 경우는 없습니다.
FixtureMonkey 인스턴스에서 Arbitrary를 생성하는 경우는 연산을 적용하지 않기 때문에 문제가 없습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 있는 테스트 중에서는 ArbitraryBuilder에서 Arbitrary를 생성해서 테스트하는 경우는 없습니다.

오픈 소스로 공개한 이상 내부 사용여부로 판단하기는 어려울거 같습니다. 저 기능을 사용하는 누군가에게는 breaking 이 되기 때문에 그것을 감수할만한 것인지 고려할 필요가 있습니다.

가능하면 @Deprecated 마킹 후에 제거하는 방향으로 순차적으로 가는게 좋긴 합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhyeon-lee
넵, 말씀드린 건 Fixture Monkey 내에 있는 테스트들인데요.
일단 0.4.0 에서 build를 depreacted 마킹하고 이후에 private으로 전환해도 되겠군요.

@@ -179,7 +180,8 @@ private ArbitraryBuilder(
return this;
}

public Arbitrary<T> build() {
@API(since = "0.4.0", status = Status.EXPERIMENTAL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공개 메소드가 아니므로 안 붙여도 될거 같습니다.
신규 메소드는 아니고 breaking 이 발생하는 부분이므로 간단하게 주석으로 이 PR 주소와 함께 breaking 한 이유를 간단하게 적어주시면 좋을거 같습니다.

@seongahjo seongahjo force-pushed the sa/refactor-convert-build-to-private branch from 1668c00 to 7ce481e Compare January 4, 2022 06:26
@mhyeon-lee
Copy link
Collaborator

짬이 좀 나서 Arbitrary 의 list, set, stream, iterator, array 정도만 구현해주면 될거 같은데요
DefaultListArbitrary, DefaultSetArbitrary, DefaultStreamArbitrary, DefaultIteratorArbitrary, DefaultArrayArbitrary 이거를 상속해서 구현해주면 될거 같은데요

이정도는 할 수 있지 않나 싶은데 더 제한되는 부분이 있나요?

@seongahjo
Copy link
Contributor Author

@mhyeon-lee
list, set, stream, iterator, array 를 구현하는 건 할 수 있는데요, Arbitrary에서 기대하는 동작은 불가능할 것 같습니다.
해당 연산을 실행하더라도 동일한 객체를 가지는 Collection만 생성이 될 것 같습니다.
따라서 Arbitrary라고 볼 수 없을 것 같아서 Arbitrary를 제거하려고 합니다.

Fixture Monkey에서 연산을 적용하다 보면 객체를 구성하는 Arbitrary들이 실제로는 Arbitrary가 아닌 Arbitrary에 wrapping한 고정 값일 확률이 높기 때문입니다.

@mhyeon-lee
Copy link
Collaborator

@seongahjo 이렇게 테스트했을 때도 같은 값이 나오는군요
같은 generator 에서 next 를 수행할 때 고정 값이 아닌 매번 새로운 값으로 생성되게 할 방법을 찾아보는게 좋을거 같습니다.

이게 해결되면 list, set, stream, array 들도 자연스럽게 문제가 해결될거 같군요

내일 일정 잡고 같이 한번 보죠

스크린샷 2022-01-04 오후 8 21 00

@seongahjo
Copy link
Contributor Author

seongahjo commented Jan 4, 2022

@mhyeon-lee
넵. 지금 #81 을 응용하여acceptIf, apply 동작 구조를 변경하고 있는데요, 주신 예제를 테스트 해보니 랜덤하게 잘 나오네요.

내일 같이 보고 jqwik 객체 생성 구조를 좀 더 알게되면 Arbitrary를 지원 가능할 것 같습니다.
제 예상에는 generator 동작에 대해 자세히 알면 될 것 같네요.

@seongahjo
Copy link
Contributor Author

#115 로 Arbitrary 인터페이스가 지원하는 기능을 제공할 수 있게 되어 닫습니다.

@seongahjo seongahjo closed this Jan 5, 2022
@seongahjo seongahjo deleted the sa/refactor-convert-build-to-private branch January 23, 2022 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants