Example #1
0
  /**
   * Test case for when item is not in cache.
   *
   * @throws SQLException
   * @throws SecurityException
   * @throws NoSuchFieldException
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   */
  @Test
  public void testStatementCacheNotInCache()
      throws SQLException, SecurityException, NoSuchFieldException, IllegalArgumentException,
          IllegalAccessException {
    CommonTestUtils.logTestInfo("Tests statement not in cache.");

    StatementCache cache = new StatementCache(5, false, null);
    assertNull(cache.get("nonExistent"));

    CommonTestUtils.logPass();
  }
Example #2
0
  /**
   * Test case method for calling different get signatures.
   *
   * @throws SQLException
   * @throws SecurityException
   * @throws NoSuchFieldException
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   */
  @Test
  public void testStatementCacheDifferentGetSignatures()
      throws SQLException, SecurityException, NoSuchFieldException, IllegalArgumentException,
          IllegalAccessException {
    CommonTestUtils.logTestInfo("Tests statement get() signatures.");

    CommonTestUtils.logTestInfo("Tests statement close (put in cache).");
    String sql = CommonTestUtils.TEST_QUERY;
    BoneCP dsb = null;
    config.setMinConnectionsPerPartition(1);
    config.setMaxConnectionsPerPartition(5);
    config.setAcquireIncrement(1);
    config.setPartitionCount(1);
    config.setStatementsCacheSize(5);
    config.setStatementReleaseHelperThreads(0);
    dsb = new BoneCP(config);
    Connection conn = dsb.getConnection();
    Statement statement = conn.prepareStatement(sql);
    statement.close();

    StatementCache cache = new StatementCache(5, false, null);
    cache.putIfAbsent("test1", (StatementHandle) statement);
    assertNotNull(cache.get("test1"));

    assertNull(cache.get("test1", 1));
    assertNull(cache.get("test1", new int[] {1}));
    assertNull(cache.get("test1", new String[] {"1"}));
    assertNull(cache.get("test1", 1, 1));
    assertNull(cache.get("test1", 1, 1, 1));

    CommonTestUtils.logPass();
  }