/*
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * 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.google.cloud.bigtable.dataflow;

import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests for {@link CloudBigtableConnectionPool}.
 */
@RunWith(JUnit4.class)
public class CloudBigtableConnectionPoolTest {

  private static Configuration config = new Configuration(false);

  private static class TestCloudbigtableConnectionPool extends CloudBigtableConnectionPool {
    @Override
    protected Connection createConnection(Configuration config) throws IOException {
      return mock(Connection.class);
    }
  }

  @Test
  public void testConnectionIsPooled() throws IOException{
    TestCloudbigtableConnectionPool pool = new TestCloudbigtableConnectionPool();
    Connection entry = pool.getConnection(config, "key");
    for (int i = 0; i < 100; i++) {
      Connection newEntry = pool.getConnection(config, "key");
      assertSame(entry, newEntry);
    }
  }

  @Test
  public void testDifferentKeys() throws IOException{
    TestCloudbigtableConnectionPool pool = new TestCloudbigtableConnectionPool();
    Connection entry1 = pool.getConnection(config, "key1");
    Connection entry2 = pool.getConnection(config, "key2");
    for (int i = 0; i < 100; i++) {
      Connection newEntry1 = pool.getConnection(config, "key1");
      assertSame(entry1, newEntry1);

      Connection newEntry2 = pool.getConnection(config, "key2");
      assertSame(entry2, newEntry2);
    }
  }
}

@@ -766,17 +766,16 @@
 eption;%0A
-%0A
 import o
@@ -849,16 +849,32 @@
 .client.
+AbstractBigtable
 Connecti
@@ -970,19 +970,16 @@
 t4;%0A%0A/**
-%0A *
  Tests f
@@ -1017,17 +1017,16 @@
 onPool%7D.
-%0A
  */%0A@Run
@@ -1280,16 +1280,32 @@
 otected 
+AbstractBigtable
 Connecti
@@ -1385,16 +1385,32 @@
 rn mock(
+AbstractBigtable
 Connecti
@@ -1488,32 +1488,33 @@
 rows IOException
+ 
 %7B%0A    TestCloudb
@@ -1577,32 +1577,48 @@
 tionPool();%0A    
+AbstractBigtable
 Connection entry
@@ -1689,32 +1689,48 @@
 0; i++) %7B%0A      
+AbstractBigtable
 Connection newEn
@@ -1876,16 +1876,17 @@
 xception
+ 
 %7B%0A    Te
@@ -1961,24 +1961,40 @@
 Pool();%0A    
+AbstractBigtable
 Connection e
@@ -2037,24 +2037,40 @@
 key1%22);%0A    
+AbstractBigtable
 Connection e
@@ -2151,24 +2151,40 @@
 ++) %7B%0A      
+AbstractBigtable
 Connection n
@@ -2274,16 +2274,32 @@
 %0A%0A      
+AbstractBigtable
 Connecti

Fix build of CloudBigtableConnectionPoolTest