Skip to content

Commit

Permalink
Rename BaseEngineParTest to BaseEngineTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Singh-Jaggi committed Oct 6, 2021
1 parent d5e112a commit 6f0d59c
Show file tree
Hide file tree
Showing 36 changed files with 253 additions and 197 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v5.1.5
------
* Rename BaseEngineParTest to BaseEngineTest

v5.1.4
------
* Add interop between Guava's ListenableFuture and Parseq Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import org.testng.annotations.Test;

import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;

public class TestBatchingSupport extends BaseEngineTest {
public class TestBatchingSupport extends BaseIsolatedEngineTest {

private final BatchingSupport _batchingSupport = new BatchingSupport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import org.testng.annotations.Test;

import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;

public class TestSimpleBatchingStrategy extends BaseEngineTest {
public class TestSimpleBatchingStrategy extends BaseIsolatedEngineTest {

private final BatchingSupport _batchingSupport = new BatchingSupport();
private final Strategy _strategy = new Strategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import org.testng.annotations.Test;

import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;
import com.linkedin.parseq.function.Failure;
import com.linkedin.parseq.function.Success;
import com.linkedin.parseq.function.Try;

public class TestTaskBatchingStrategy extends BaseEngineTest {
public class TestTaskBatchingStrategy extends BaseIsolatedEngineTest {

private final BatchingSupport _batchingSupport = new BatchingSupport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import org.testng.annotations.Test;

import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;
import com.linkedin.parseq.function.Success;
import com.linkedin.parseq.function.Try;

public class TestTaskSimpleBatchingStrategy extends BaseEngineTest {
public class TestTaskSimpleBatchingStrategy extends BaseIsolatedEngineTest {

private final BatchingSupport _batchingSupport = new BatchingSupport();
private final Strategy _strategy = new Strategy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.linkedin.parseq.batching;

import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;
import com.linkedin.parseq.function.Success;
Expand All @@ -20,7 +20,7 @@
import static org.testng.AssertJUnit.*;


public class TestTaskSimpleBatchingStrategyBlocking extends BaseEngineTest {
public class TestTaskSimpleBatchingStrategyBlocking extends BaseIsolatedEngineTest {

private final ScheduledExecutorService _executorService = Executors.newScheduledThreadPool(10);
private final BatchingSupport _batchingSupport = new BatchingSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

import com.linkedin.common.callback.FutureCallback;
import com.linkedin.common.util.None;
import com.linkedin.parseq.BaseEngineTest;
import com.linkedin.parseq.BaseIsolatedEngineTest;
import com.linkedin.parseq.Engine;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.Task;
Expand All @@ -58,7 +58,7 @@
import com.linkedin.restli.examples.greetings.client.GreetingsBuilders;


public abstract class ParSeqRestClientIntegrationTest extends BaseEngineTest {
public abstract class ParSeqRestClientIntegrationTest extends BaseIsolatedEngineTest {

private static final AtomicInteger PORTER = new AtomicInteger(14497);
private final int _port = PORTER.getAndIncrement();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ([email protected])
* An alias for {@link BaseEngineTest}, only kept for backwards compatibility. Please use the latter.
* @author Anmol Singh Jaggi ([email protected])
*/
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
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,98 +16,39 @@

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 ([email protected])
* @author Jaroslaw Odzga ([email protected])
*
* @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();
}
}

/**
* 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();
}
@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 @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());
}
}

protected void customizeEngine(EngineBuilder engineBuilder) {
}

}
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
* @author Jaroslaw Odzga ([email protected])
*
* @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 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());
}
}
}

protected void customizeEngine(EngineBuilder engineBuilder) {
}

}
Loading

0 comments on commit 6f0d59c

Please sign in to comment.