From 2cbafed2ac013e3ab6a222ea1b64cf79c993d975 Mon Sep 17 00:00:00 2001 From: Anmol Singh Jaggi Date: Wed, 6 Oct 2021 10:33:05 +0530 Subject: [PATCH] Rename BaseEngineParTest to BaseEngineTest --- CHANGELOG.md | 4 + .../linkedin/parseq/BaseEngineParTest.java | 40 +----- .../com/linkedin/parseq/BaseEngineTest.java | 101 ++++------------ .../parseq/BaseIsolatedEngineTest.java | 114 ++++++++++++++++++ .../linkedin/parseq/OldBaseEngineTest.java | 64 ++++++++++ .../BaseEngineJunitJupiterTest.java | 56 +++++++++ .../BaseEngineParJunitJupiterTest.java | 41 +------ ...> BaseIsolatedEngineJUnitJupiterTest.java} | 8 +- .../OldBaseEngineJunitJupiterTest.java | 37 ++++++ 9 files changed, 313 insertions(+), 152 deletions(-) create mode 100644 subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseIsolatedEngineTest.java create mode 100644 subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/OldBaseEngineTest.java create mode 100644 subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJunitJupiterTest.java rename subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/{BaseEngineJUnitJupiterTest.java => BaseIsolatedEngineJUnitJupiterTest.java} (85%) create mode 100644 subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/OldBaseEngineJunitJupiterTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc943df..5904461a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v5.1.5 +------ +* Rename BaseEngineParTest to BaseEngineTest + v5.1.4 ------ * Add interop between Guava's ListenableFuture and Parseq Task diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineParTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineParTest.java index 24070815..9cf87432 100644 --- a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineParTest.java +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineParTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 LinkedIn, Inc + * Copyright 2021 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -16,39 +16,11 @@ package com.linkedin.parseq; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; - - /** - * A base class that builds an Engine with default configuration. - * For JUnit Jupiter (JUnit5+), see {@link com.linkedin.parseq.junitjupiter.BaseEngineParJunitJupiterTest}. - * - * This class creates new Engine before any test method is run and shuts it down after all tests are finished. - * It can be used to run tests in parallel. - * - * The difference between this class and {@link BaseEngineTest} is that {@code BaseEngineTest} creates new - * {@code Engine} instance for every test and thus provides higher level of isolation between the tests. - * - * @author Jaroslaw Odzga (jodzga@linkedin.com) + * An alias for {@link BaseEngineTest}, only kept for backwards compatibility. Please use the latter. + * @author Anmol Singh Jaggi (ajaggi@linkedin.com) */ -public class BaseEngineParTest extends AbstractBaseEngineTest { - - @BeforeClass - public void setUpBaseEngineParTest() throws Exception { - getParSeqUnitTestHelper().setUp(); - } - - @AfterClass - public void tearDownBaseEngineParTest() throws Exception { - if (getEngine() != null) { - getParSeqUnitTestHelper().tearDown(); - } else { - throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " - + "already been shut down, in " + this.getClass().getName()); - } - } - - protected void customizeEngine(EngineBuilder engineBuilder) { - } +@Deprecated +public class BaseEngineParTest extends BaseEngineTest { + // Empty } diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineTest.java index 2d2bedd0..2d157f2d 100644 --- a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineTest.java +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseEngineTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 LinkedIn, Inc + * Copyright 2017 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -16,98 +16,41 @@ package com.linkedin.parseq; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; /** * A base class that builds an Engine with default configuration. - * For JUnit Jupiter (JUnit5+), see {@link com.linkedin.parseq.junitjupiter.BaseEngineJUnitJupiterTest} + * For JUnit Jupiter (JUnit5+), see {@link com.linkedin.parseq.junitjupiter.BaseEngineJunitJupiterTest}. * - * This class creates new Engine and shuts it down before and after every test method, so it can't be used - * to run tests in parallel. + * This class creates new Engine before any test method is run and shuts it down after all tests are finished. + * It can be used to run tests in parallel. * - * The difference between this class and {@link BaseEngineParTest} is that {@code BaseEngineParTest} creates new - * {@code Engine} instance only once for all tests in the class and thus can be used to run test methods in parallel. + * The difference between this class and {@link BaseIsolatedEngineTest} is that the latter creates a new + * {@code Engine} instance for every test and thus provides higher level of isolation between the tests. * - * @author Chris Pettitt (cpettitt@linkedin.com) * @author Jaroslaw Odzga (jodzga@linkedin.com) - * - * @see ParSeqUnitTestHelper - * @see BaseEngineParTest */ -public class BaseEngineTest extends AbstractBaseEngineTest { - - private volatile boolean _setUpCalled = false; - private volatile boolean _tearDownCalled = false; - - @BeforeMethod - public void setUpBaseEngineTest() throws Exception { - if (!_setUpCalled) { - _setUpCalled = true; - _tearDownCalled = false; - getParSeqUnitTestHelper().setUp(); - } +public class BaseEngineTest extends OldBaseEngineTest { + + @BeforeClass + public void setUpBaseEngineParTest() throws Exception { + getParSeqUnitTestHelper().setUp(); } - /** - * This method is left for backwards compatibility purpose. - * It is not a good idea to have a @BeforeMethod method named - * setUp because chances are that subclass will accidentally - * override this method. - * TODO in next major version this method should be removed - * @deprecated - */ - @Deprecated - @BeforeMethod - public void setUp() throws Exception { - if (!_setUpCalled) { - _setUpCalled = true; - _tearDownCalled = false; - getParSeqUnitTestHelper().setUp(); - } - } - - /** - * This method is left for backwards compatibility purpose. - * It is not a good idea to have a @AfterMethod method named - * tearDown because chances are that subclass will accidentally - * override this method. - * TODO in next major version this method should be removed - * @deprecated - */ - @Deprecated - @AfterMethod - public void tearDown() throws Exception { - if (!_tearDownCalled) { - _setUpCalled = false; - _tearDownCalled = true; - if (getEngine() != null) { - getParSeqUnitTestHelper().tearDown(); - } else { - throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " - + "already been shut down. Please make sure you are not running unit tests in parallel. If you need to " - + "run unit tests in parallel, then use BaseEngineParTest instead, in " + this.getClass().getName()); - } - } - } - - @AfterMethod - public void tearDownBaseEngineTest() throws Exception { - if (!_tearDownCalled) { - _setUpCalled = false; - _tearDownCalled = true; - if (getEngine() != null) { - getParSeqUnitTestHelper().tearDown(); - } else { - throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " - + "already been shut down. Please make sure you are not running unit tests in parallel. If you need to " - + "run unit tests in parallel, then use BaseEngineParTest instead, in " + this.getClass().getName()); - } + @AfterClass + public void tearDownBaseEngineParTest() throws Exception { + if (getEngine() != null) { + getParSeqUnitTestHelper().tearDown(); + } else { + throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " + + "already been shut down, in " + this.getClass().getName()); } } + @Override protected void customizeEngine(EngineBuilder engineBuilder) { + } - } diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseIsolatedEngineTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseIsolatedEngineTest.java new file mode 100644 index 00000000..313075d0 --- /dev/null +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/BaseIsolatedEngineTest.java @@ -0,0 +1,114 @@ +/* + * Copyright 2012 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.linkedin.parseq; + +import com.linkedin.parseq.junitjupiter.BaseIsolatedEngineJUnitJupiterTest; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + + +/** + * A base class that builds an Engine with default configuration. + * For JUnit Jupiter (JUnit5+), see {@link BaseIsolatedEngineJUnitJupiterTest} + * + * This class creates a new Engine and shuts it down before and after every test method, so it can't be used + * to run tests in parallel. + * + * The difference between this class and {@link BaseEngineTest} is that the latter creates a new + * {@code Engine} instance only once for all tests in the class and thus can be used to run test methods in parallel. + * + * @author Chris Pettitt (cpettitt@linkedin.com) + * @author Jaroslaw Odzga (jodzga@linkedin.com) + * + * @see ParSeqUnitTestHelper + * @see BaseEngineTest + */ +public class BaseIsolatedEngineTest extends AbstractBaseEngineTest { + + private volatile boolean _setUpCalled = false; + private volatile boolean _tearDownCalled = false; + + @BeforeMethod + public void setUpBaseEngineTest() throws Exception { + if (!_setUpCalled) { + _setUpCalled = true; + _tearDownCalled = false; + getParSeqUnitTestHelper().setUp(); + } + } + + /** + * This method is left for backwards compatibility purpose. + * It is not a good idea to have a @BeforeMethod method named + * setUp because chances are that subclass will accidentally + * override this method. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @BeforeMethod + public void setUp() throws Exception { + if (!_setUpCalled) { + _setUpCalled = true; + _tearDownCalled = false; + getParSeqUnitTestHelper().setUp(); + } + } + + /** + * This method is left for backwards compatibility purpose. + * It is not a good idea to have a @AfterMethod method named + * tearDown because chances are that subclass will accidentally + * override this method. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @AfterMethod + public void tearDown() throws Exception { + if (!_tearDownCalled) { + _setUpCalled = false; + _tearDownCalled = true; + if (getEngine() != null) { + getParSeqUnitTestHelper().tearDown(); + } else { + throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " + + "already been shut down. Please make sure you are not running unit tests in parallel. If you need to " + + "run unit tests in parallel, then use BaseEngineTest instead, in " + this.getClass().getName()); + } + } + } + + @AfterMethod + public void tearDownBaseEngineTest() throws Exception { + if (!_tearDownCalled) { + _setUpCalled = false; + _tearDownCalled = true; + if (getEngine() != null) { + getParSeqUnitTestHelper().tearDown(); + } else { + throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " + + "already been shut down. Please make sure you are not running unit tests in parallel. If you need to " + + "run unit tests in parallel, then use BaseEngineTest instead, in " + this.getClass().getName()); + } + } + } + + protected void customizeEngine(EngineBuilder engineBuilder) { + } + +} diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/OldBaseEngineTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/OldBaseEngineTest.java new file mode 100644 index 00000000..32066214 --- /dev/null +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/OldBaseEngineTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2021 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.linkedin.parseq; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + + +abstract class OldBaseEngineTest extends AbstractBaseEngineTest { + + /** + * This method is left for backwards compatibility purpose. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @BeforeMethod + public void setUpBaseEngineTest() throws Exception { + } + + /** + * This method is left for backwards compatibility purpose. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @BeforeMethod + public void setUp() throws Exception { + } + + /** + * This method is left for backwards compatibility purpose. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @AfterMethod + public void tearDown() throws Exception { + } + + /** + * This method is left for backwards compatibility purpose. + * TODO in next major version this method should be removed + * @deprecated + */ + @Deprecated + @AfterMethod + public void tearDownBaseEngineTest() throws Exception { + } +} diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJunitJupiterTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJunitJupiterTest.java new file mode 100644 index 00000000..8ce5f4d3 --- /dev/null +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJunitJupiterTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.linkedin.parseq.junitjupiter; + +import com.linkedin.parseq.AbstractBaseEngineTest; +import com.linkedin.parseq.EngineBuilder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; + + +/** + * A base class that builds an Engine with default configuration. + * Requires JUnit Jupiter (JUnit5+) + * + * This class creates a new Engine before any test method is run and shuts it down after all tests are finished. + * It can be used to run tests in parallel. + * + * The difference between this class and {@link BaseIsolatedEngineJUnitJupiterTest} is that the latter creates a new + * {@code Engine} instance for every test and thus provides higher level of isolation between the tests. + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class BaseEngineJunitJupiterTest extends OldBaseEngineJunitJupiterTest { + + @BeforeAll + public void setUpBaseEngineParTest() throws Exception { + getParSeqUnitTestHelper().setUp(); + } + + @AfterAll + public void tearDownBaseEngineParTest() throws Exception { + if (getEngine() != null) { + getParSeqUnitTestHelper().tearDown(); + } else { + throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " + + "already been shut down, in " + this.getClass().getName()); + } + } + + protected void customizeEngine(EngineBuilder engineBuilder) { + } +} diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineParJunitJupiterTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineParJunitJupiterTest.java index 9e205444..606c8c02 100644 --- a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineParJunitJupiterTest.java +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineParJunitJupiterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 LinkedIn, Inc + * Copyright 2021 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -16,41 +16,12 @@ package com.linkedin.parseq.junitjupiter; -import com.linkedin.parseq.AbstractBaseEngineTest; -import com.linkedin.parseq.EngineBuilder; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.TestInstance; - /** - * A base class that builds an Engine with default configuration. - * Requires JUnit Jupiter (JUnit5+) - * - * This class creates new Engine before any test method is run and shuts it down after all tests are finished. - * It can be used to run tests in parallel. - * - * The difference between this class and {@link BaseEngineJUnitJupiterTest} is that {@code BaseEngineJUnitJupiterTest} creates new - * {@code Engine} instance for every test and thus provides higher level of isolation between the tests. + * An alias for {@link BaseEngineJunitJupiterTest}, only kept for backwards compatibility. Please use the latter. + * @author Anmol Singh Jaggi (ajaggi@linkedin.com) */ -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class BaseEngineParJunitJupiterTest extends AbstractBaseEngineTest { - - @BeforeAll - public void setUpBaseEngineParTest() throws Exception { - getParSeqUnitTestHelper().setUp(); - } - - @AfterAll - public void tearDownBaseEngineParTest() throws Exception { - if (getEngine() != null) { - getParSeqUnitTestHelper().tearDown(); - } else { - throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " - + "already been shut down, in " + this.getClass().getName()); - } - } - - protected void customizeEngine(EngineBuilder engineBuilder) { - } +@Deprecated +public class BaseEngineParJunitJupiterTest extends BaseEngineJunitJupiterTest { + // Empty } diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJUnitJupiterTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseIsolatedEngineJUnitJupiterTest.java similarity index 85% rename from subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJUnitJupiterTest.java rename to subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseIsolatedEngineJUnitJupiterTest.java index 03bdb245..2d6ce04e 100644 --- a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseEngineJUnitJupiterTest.java +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/BaseIsolatedEngineJUnitJupiterTest.java @@ -30,13 +30,13 @@ * This class creates new Engine and shuts it down before and after every test method, so it can't be used * to run tests in parallel. * - * The difference between this class and {@link BaseEngineParJunitJupiterTest} is that {@code BaseEngineParJunitJupiterTest} creates new + * The difference between this class and {@link BaseEngineJunitJupiterTest} is that the latter creates a new * {@code Engine} instance only once for all tests in the class and thus can be used to run test methods in parallel. * * @see ParSeqUnitTestHelper - * @see BaseEngineParJunitJupiterTest + * @see BaseEngineJunitJupiterTest */ -public class BaseEngineJUnitJupiterTest extends AbstractBaseEngineTest { +public class BaseIsolatedEngineJUnitJupiterTest extends AbstractBaseEngineTest { private volatile boolean _setUpCalled = false; private volatile boolean _tearDownCalled = false; @@ -60,7 +60,7 @@ public void tearDownBaseEngineTest() throws Exception { } else { throw new RuntimeException("Tried to shut down Engine but it either has not even been created or has " + "already been shut down. Please make sure you are not running unit tests in parallel. If you need to " - + "run unit tests in parallel, then use BaseEngineParJunitJupiterTest instead, in " + this.getClass().getName()); + + "run unit tests in parallel, then use BaseEngineJunitJupiterTest instead, in " + this.getClass().getName()); } } } diff --git a/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/OldBaseEngineJunitJupiterTest.java b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/OldBaseEngineJunitJupiterTest.java new file mode 100644 index 00000000..7d26bd79 --- /dev/null +++ b/subprojects/parseq-test-api/src/main/java/com/linkedin/parseq/junitjupiter/OldBaseEngineJunitJupiterTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2021 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.linkedin.parseq.junitjupiter; + +import com.linkedin.parseq.AbstractBaseEngineTest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInstance; + + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +abstract class OldBaseEngineJunitJupiterTest extends AbstractBaseEngineTest { + + @Deprecated + @BeforeEach + public void setUpBaseEngineTest() throws Exception { + } + + @Deprecated + @AfterEach + public void tearDownBaseEngineTest() throws Exception { + } +}