@Before
  public void onSetUp() throws Exception {

    JdbcTestUtils.executeSqlScript(
        new JdbcTemplate(dataSource),
        new ClassPathResource("META-INF/testdata/sample_schema_ddl_" + usingDBMS + ".sql"),
        true);

    // init data
    JdbcTestUtils.executeSqlScript(
        new JdbcTemplate(dataSource),
        new ClassPathResource("META-INF/testdata/sample_schema_initdata_" + usingDBMS + ".sql"),
        true);
  }
  @Bean
  public BasicDataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(environment.getProperty("jdbc.driverClassName"));
    basicDataSource.setUrl(environment.getProperty("jdbc.url"));
    basicDataSource.setUsername(environment.getProperty("jdbc.username"));
    basicDataSource.setPassword(environment.getProperty("jdbc.password"));

    // properties below are to improve performance
    basicDataSource.setTestWhileIdle(true);
    basicDataSource.setTestOnBorrow(true);
    basicDataSource.setTestOnReturn(false);
    basicDataSource.setValidationQuery(environment.getProperty("jdbc.validationQuery"));
    basicDataSource.setTimeBetweenEvictionRunsMillis(30000);
    basicDataSource.setMaxActive(100);
    basicDataSource.setMinIdle(10);
    basicDataSource.setMaxWait(10000);
    basicDataSource.setInitialSize(10);
    basicDataSource.setRemoveAbandonedTimeout(60);
    basicDataSource.setRemoveAbandoned(true);
    basicDataSource.setLogAbandoned(true);
    basicDataSource.setMinEvictableIdleTimeMillis(30000);

    // create scheme
    if (!"false".equals(System.getProperty("create_scheme"))) {
      JdbcTestUtils.executeSqlScript(
          new JdbcTemplate(basicDataSource),
          new ClassPathResource("/sql/create_scheme.sql"),
          false);
    }
    return basicDataSource;
  }
Esempio n. 3
0
 protected void getValue(
     ICounterStore counterStore, String counter, int rows, int tableValue, int counterValue) {
   final int v = counterStore.getNextId(counter);
   assertEquals("counterValue", counterValue, v);
   assertEquals("rows", rows, JdbcTestUtils.countRowsInTable(jdbcTemplate, "UP_SEQUENCE"));
   assertEquals(
       "tableValue",
       tableValue,
       (int)
           jdbcTemplate.queryForObject(
               "SELECT SEQUENCE_VALUE FROM UP_SEQUENCE WHERE SEQUENCE_NAME=?",
               Integer.class,
               counter));
 }
Esempio n. 4
0
  @Test
  public void testCounterSingleThread() {
    // Get until DB has to increment
    this.getValue(this.counterStoreOne, "Test1", 1, 7, 1);

    this.getValue(this.counterStoreTwo, "Test1", 1, 10, 4);

    this.getValue(this.counterStoreOne, "Test1", 1, 10, 2);

    this.getValue(this.counterStoreTwo, "Test1", 1, 10, 5);

    this.getValue(this.counterStoreOne, "Test1", 1, 10, 3);

    this.getValue(this.counterStoreTwo, "Test1", 1, 10, 6);

    this.getValue(this.counterStoreOne, "Test1", 1, 13, 7);

    this.getValue(this.counterStoreTwo, "Test1", 1, 16, 10);

    this.getValue(this.counterStoreOne, "Test1", 1, 16, 8);

    this.getValue(this.counterStoreTwo, "Test1", 1, 16, 11);

    this.getValue(this.counterStoreOne, "Test1", 1, 16, 9);

    this.getValue(this.counterStoreOne, "Test1", 1, 19, 13);

    this.getValue(this.counterStoreOne, "Test2", 2, 7, 1);

    this.getValue(this.counterStoreTwo, "Test2", 2, 10, 4);

    assertEquals("rowCount", 2, JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "UP_SEQUENCE"));
    assertEquals(
        "Test1 counter value",
        19,
        (int)
            jdbcTemplate.queryForObject(
                "SELECT SEQUENCE_VALUE FROM UP_SEQUENCE WHERE SEQUENCE_NAME=?",
                Integer.class,
                "Test1"));
    assertEquals(
        "Test2 counter value",
        10,
        (int)
            jdbcTemplate.queryForObject(
                "SELECT SEQUENCE_VALUE FROM UP_SEQUENCE WHERE SEQUENCE_NAME=?",
                Integer.class,
                "Test2"));
  }
Esempio n. 5
0
 @Before
 public void onSetUp() throws Exception {
   jdbcTemplate.update(
       "CREATE TABLE UP_SEQUENCE (SEQUENCE_NAME VARCHAR(1000), SEQUENCE_VALUE INTEGER)");
   assertEquals(0, JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "UP_SEQUENCE"));
 }
 protected void assertNumUsers(int expected) {
   assertEquals(
       "Number of rows in the 'user' table.",
       expected,
       JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
 }