Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
  /**
   * Test limits.
   *
   * @throws SQLException
   * @throws SecurityException
   * @throws NoSuchFieldException
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   */
  @Test
  public void testStatementCacheLimits()
      throws SQLException, SecurityException, NoSuchFieldException, IllegalArgumentException,
          IllegalAccessException {
    CommonTestUtils.logTestInfo("Tests statement caching module.");
    String sql = CommonTestUtils.TEST_QUERY;
    BoneCP dsb = null;
    config.setMinConnectionsPerPartition(2);
    config.setMaxConnectionsPerPartition(5);
    config.setAcquireIncrement(1);
    config.setPartitionCount(1);
    config.setStatementsCacheSize(5);
    dsb = new BoneCP(config);
    Connection conn = dsb.getConnection();
    StatementHandle statement = (StatementHandle) conn.prepareStatement(sql);

    StatementCache cache = new StatementCache(5, true, new Statistics(dsb));
    cache.putIfAbsent("test1", statement);
    cache.putIfAbsent("test2", statement);
    cache.putIfAbsent("test3", statement);
    cache.putIfAbsent("test4", statement);
    cache.putIfAbsent("test5", statement);

    conn.close();

    for (int i = 0; i < 5000000; i++) {
      cache.putIfAbsent("test" + i, statement);
      if ((i % 10000) == 0) {
        System.gc();
      }
      if (cache.size() != i) {
        break;
      }
    }
    // some elements should have been dropped in the cache
    assertFalse(cache.size() == 5000000);

    dsb.shutdown();
    CommonTestUtils.logPass();
  }