@@ -0,0 +1,3420 @@
+/**%0A * Copyright 2016 Palantir Technologies%0A *%0A * Licensed under the BSD-3 License (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://opensource.org/licenses/BSD-3-Clause%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.palantir.atlasdb.keyvalue.dbkvs.impl;%0A%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Matchers.anyObject;%0Aimport static org.mockito.Matchers.eq;%0Aimport static org.mockito.Matchers.startsWith;%0Aimport static org.mockito.Mockito.doReturn;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport java.sql.Connection;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.palantir.atlasdb.AtlasDbConstants;%0Aimport com.palantir.atlasdb.keyvalue.api.TableReference;%0Aimport com.palantir.nexus.db.sql.AgnosticResultRow;%0Aimport com.palantir.nexus.db.sql.AgnosticResultSet;%0Aimport com.palantir.nexus.db.sql.SqlConnection;%0A%0Apublic class TableSizeCacheTest %7B%0A    private static final TableReference TEST_TABLE = TableReference.createFromFullyQualifiedName(%22ns.test_table%22);%0A    ConnectionSupplier conns = mock(ConnectionSupplier.class);%0A    TableSizeCache tableSizeCache = new TableSizeCache(conns, AtlasDbConstants.DEFAULT_METADATA_TABLE);%0A%0A    @Before%0A    public void setup() %7B%0A        SqlConnection mockConnection =  mock(SqlConnection.class);%0A        when(conns.getNewUnsharedConnection()).thenReturn(mockConnection);%0A%0A        AgnosticResultSet resultSet = mock(AgnosticResultSet.class);%0A        when(mockConnection.selectResultSetUnregisteredQuery(startsWith(%22SELECT table_size FROM%22), anyObject()))%0A                .thenReturn(resultSet);%0A%0A        AgnosticResultRow row = mock(AgnosticResultRow.class);%0A        when(row.getInteger(eq(%22table_size%22))).thenReturn(TableSize.OVERFLOW.getId());%0A        doReturn(ImmutableList.of(row)).when(resultSet).rows();%0A%0A        when(mockConnection.getUnderlyingConnection()).thenReturn(mock(Connection.class));%0A    %7D%0A%0A    @Test%0A    public void testGetTableSizeOneTimeHasCacheMiss() throws Exception %7B%0A        assertThat(tableSizeCache.getTableSize(TEST_TABLE), is(TableSize.OVERFLOW));%0A        verify(conns, times(1)).getNewUnsharedConnection();%0A    %7D%0A%0A%0A    @Test%0A    public void testGetTableSizeForSameTableHitsCache() throws Exception %7B%0A        assertThat(tableSizeCache.getTableSize(TEST_TABLE), is(TableSize.OVERFLOW));%0A        assertThat(tableSizeCache.getTableSize(TEST_TABLE), is(TableSize.OVERFLOW));%0A%0A        verify(conns, times(1)).getNewUnsharedConnection();%0A    %7D%0A%0A    @Test%0A    public void testCacheInvalidationHitsConnectionAgain() throws Exception %7B%0A        assertThat(tableSizeCache.getTableSize(TEST_TABLE), is(TableSize.OVERFLOW));%0A        tableSizeCache.clearCacheForTable(TEST_TABLE);%0A        assertThat(tableSizeCache.getTableSize(TEST_TABLE), is(TableSize.OVERFLOW));%0A%0A        verify(conns, times(2)).getNewUnsharedConnection();%0A    %7D%0A%7D%0A

Add unit tests