Skip to content

Commit

Permalink
test: rename integration test (#347)
Browse files Browse the repository at this point in the history
* test: rename integration test

Rename the SessionPoolIntegrationTest to IT... so it is actually picked up
by the configuration that executes the integration tests.

* cleanup: move declaration to try-with-resources block
  • Loading branch information
olavloite committed Jul 17, 2020
1 parent 0f99196 commit cea51ad
Showing 1 changed file with 17 additions and 15 deletions.
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand All @@ -41,7 +42,7 @@
*/
@Category(IntegrationTest.class)
@RunWith(JUnit4.class)
public class SessionPoolIntegrationTest {
public class ITSessionPoolIntegrationTest {
@ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv();
private static final String TABLE_NAME = "TestTable";

Expand Down Expand Up @@ -97,28 +98,27 @@ public ScheduledExecutorService get() {

@Test
public void sessionCreation() {
try (Session session = pool.getReadSession()) {
assertThat(session).isNotNull();
try (PooledSessionFuture session = pool.getReadSession()) {
assertThat(session.get()).isNotNull();
}

try (Session session = pool.getReadSession()) {
assertThat(session).isNotNull();
Session session2 = pool.getReadSession();
assertThat(session2).isNotNull();
session2.close();
try (PooledSessionFuture session = pool.getReadSession();
PooledSessionFuture session2 = pool.getReadSession()) {
assertThat(session.get()).isNotNull();
assertThat(session2.get()).isNotNull();
}
}

@Test
public void poolExhaustion() throws Exception {
Session session1 = pool.getReadSession();
Session session2 = pool.getReadSession();
Session session1 = pool.getReadSession().get();
Session session2 = pool.getReadSession().get();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(
new Runnable() {
@Override
public void run() {
try (Session session3 = pool.getReadSession()) {
try (Session session3 = pool.getReadSession().get()) {
latch.countDown();
}
}
Expand All @@ -132,16 +132,16 @@ public void run() {

@Test
public void multipleWaiters() throws Exception {
Session session1 = pool.getReadSession();
Session session2 = pool.getReadSession();
Session session1 = pool.getReadSession().get();
Session session2 = pool.getReadSession().get();
int numSessions = 5;
final CountDownLatch latch = new CountDownLatch(numSessions);
for (int i = 0; i < numSessions; i++) {
new Thread(
new Runnable() {
@Override
public void run() {
try (Session session = pool.getReadSession()) {
try (Session session = pool.getReadSession().get()) {
latch.countDown();
}
}
Expand All @@ -167,7 +167,9 @@ public void closeAfterInitialCreateDoesNotBlockIndefinitely() throws Exception {

@Test
public void closeWhenSessionsActiveFinishes() throws Exception {
Session session = pool.getReadSession();
pool.getReadSession().get();
// This will log a warning that a session has been leaked, as the session that we retrieved in
// the previous statement was never returned to the pool.
pool.closeAsync(new SpannerImpl.ClosedException()).get();
}
}

0 comments on commit cea51ad

Please sign in to comment.