@BeforeTest
  public void createConnection() throws Exception {
    JdbcStringBasedStoreConfigurationBuilder storeBuilder =
        TestCacheManagerFactory.getDefaultCacheConfiguration(false)
            .persistence()
            .addStore(JdbcStringBasedStoreConfigurationBuilder.class);
    UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table(), false);
    factoryConfiguration =
        UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
    tableManipulation = new TableManipulation(storeBuilder.table().create());

    if (factoryConfiguration instanceof SimpleConnectionFactoryConfiguration) {
      SimpleConnectionFactoryConfiguration simpleConfiguration =
          (SimpleConnectionFactoryConfiguration) factoryConfiguration;
      connection =
          DriverManager.getConnection(
              simpleConfiguration.connectionUrl(),
              simpleConfiguration.username(),
              simpleConfiguration.password());

    } else if (factoryConfiguration instanceof PooledConnectionFactoryConfiguration) {
      PooledConnectionFactoryConfiguration pooledConfiguration =
          (PooledConnectionFactoryConfiguration) factoryConfiguration;
      connection =
          DriverManager.getConnection(
              pooledConfiguration.connectionUrl(),
              pooledConfiguration.username(),
              pooledConfiguration.password());
    }
    tableManipulation.setCacheName("aName");
  }
 @Override
 protected void configurePersistence(ConfigurationBuilder cb) {
   JdbcStringBasedStoreConfigurationBuilder storeBuilder =
       cb.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
   UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder);
   UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table(), false);
 }
  public void testConnectionLeakGuessDatabaseType() throws Exception {
    JdbcStringBasedStoreConfigurationBuilder storeBuilder =
        TestCacheManagerFactory.getDefaultCacheConfiguration(false)
            .persistence()
            .addStore(JdbcStringBasedStoreConfigurationBuilder.class);

    UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table(), false);

    TableManipulation tableManipulation = new TableManipulation(storeBuilder.table().create());
    // database type must now be determined
    tableManipulation.databaseType = null;
    tableManipulation.setCacheName("GuessDatabaseType");

    PooledConnectionFactory factory = new PooledConnectionFactory();
    ConnectionFactoryConfiguration config =
        UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
    factory.start(config, Thread.currentThread().getContextClassLoader());
    tableManipulation.start(factory);
    tableManipulation.getUpdateRowSql();
    UnitTestDatabaseManager.verifyConnectionLeaks(factory);
    tableManipulation.stop();
    factory.stop();
  }
示例#4
0
  @Bean
  public SpringEmbeddedCacheManagerFactoryBean cacheManagerFactoryBean() throws Exception {
    // JGroups settings
    String jgroupsConfigurationFile = environment.getRequiredProperty("jgroups.configurationFile");
    if ("jgroups-ec2.xml".equals(jgroupsConfigurationFile)) {
      ClassConfigurator.addProtocol((short) 1000, S3_CLIENT_PING.class);

      EC2MetadataClient metadataClient = new EC2MetadataClient();
      String ipAddress = metadataClient.readResource("/latest/meta-data/local-ipv4");
      logger.info("jgroups.tcp.address -> {}", ipAddress);
      System.setProperty("jgroups.tcp.address", ipAddress);
      System.setProperty("jgroups.s3.bucket", environment.getRequiredProperty("jgroups.s3.bucket"));
    }

    ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder();

    GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder();
    // @formatter:off
    globalBuilder
        .globalJmxStatistics()
        .enable()
        //				.cacheManagerName("HibernateSearch")
        .allowDuplicateDomains(true)
        .transport()
        .defaultTransport()
        //				.clusterName("wallride-cluster")
        .addProperty("configurationFile", jgroupsConfigurationFile);
    // @formatter:on

    Properties props = new Properties();
    props.put("hibernate.search.default.directory_provider", "infinispan");
    //		props.put("hibernate.search.default.indexmanager",
    // InfinispanIndexManager.class.getCanonicalName());
    props.put("hibernate.search.default.indexmanager", "near-real-time");
    props.put("hibernate.search.default.exclusive_index_use", "false");

    ConfigurationBuilder defaultBuilder = holder.getDefaultConfigurationBuilder();

    JdbcStringBasedStoreConfigurationBuilder jdbcBuilder =
        new JdbcStringBasedStoreConfigurationBuilder(defaultBuilder.persistence());
    //		JdbcStringBasedCacheStoreConfigurationBuilder jdbcBuilder = new
    // JdbcStringBasedCacheStoreConfigurationBuilder(defaultBuilder.loaders());
    // @formatter:off
    jdbcBuilder
        .key2StringMapper(LuceneKey2StringMapper.class)
        .table()
        .tableNamePrefix("ispn_string_table")
        .idColumnName("id_column")
        .idColumnType("varchar(255)")
        .dataColumnName("data_column")
        .dataColumnType("longblob")
        .timestampColumnName("timestamp_column")
        .timestampColumnType("bigint")
        .dropOnExit(false)
        .createOnStart(true)
        .async()
        .enable()
        .flushLockTimeout(15000)
        .threadPoolSize(10)
        .fetchPersistentState(true)
        .ignoreModifications(false)
        .purgeOnStartup(false)
        //			.dataSource().jndiUrl("dataSource");
        .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class)
        .dataSource(dataSource);
    // @formatter:on

    // @formatter:off
    defaultBuilder
        .clustering()
        .cacheMode(CacheMode.DIST_SYNC)
        //			.locking()
        //				.lockAcquisitionTimeout(300000)
        //				.writeSkewCheck(false)
        //				.concurrencyLevel(500)
        //				.useLockStriping(false)
        //			.stateTransfer()
        //				.timeout(960000)
        //				.fetchInMemoryState(true)
        //			.sync()
        //			.replTimeout(480000)
        //				.jmxStatistics()
        //				.enable()
        //			.eviction()
        //				.maxEntries(-1)
        //				.strategy(EvictionStrategy.NONE)
        //				.expiration()
        //					.maxIdle(-1)
        //					.reaperEnabled(false)
        //			.indexing()
        //				.index(Index.LOCAL)
        //				.enable()
        //				.indexLocalOnly(false)
        //				.withProperties(props)
        .persistence()
        .addStore(jdbcBuilder)
        .preload(true)
        .shared(true);
    // @formatter:on

    //		ConfigurationBuilder luceneBuilder = new ConfigurationBuilder();
    //		luceneBuilder
    //			.clustering()
    //				.cacheMode(CacheMode.REPL_SYNC)
    //				.stateTransfer()
    //					.fetchInMemoryState(true)
    //				.sync()
    //					.replTimeout(480000)
    //			.indexing()
    //					.enabled(false);
    //
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesMetadata", luceneBuilder);
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesData", luceneBuilder);
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesLocking", luceneBuilder);

    ConfigurationBuilder cacheBuilder = new ConfigurationBuilder();
    // @formatter:off
    cacheBuilder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC).indexing().index(Index.NONE);
    //			.persistence()
    //				.clearStores();
    // @formatter:on

    holder.getNamedConfigurationBuilders().put("blogs", cacheBuilder);
    //		holder.getNamedConfigurationBuilders().put("settings", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("popularPosts", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("articles", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("categories", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("pages", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("medias", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("banners", cacheBuilder);

    //		holder.getNamedConfigurationBuilders().put("resources", cacheBuilder);

    //		final EmbeddedCacheManager embeddedCacheManager = new
    // DefaultCacheManager(globalBuilder.build(), cacheBuilder.build());
    final EmbeddedCacheManager embeddedCacheManager = new DefaultCacheManager(holder, true);

    InfinispanSingletonCacheManagerDirectoryProvider.cacheManager = embeddedCacheManager;

    SpringEmbeddedCacheManagerFactoryBean factory =
        new SpringEmbeddedCacheManagerFactoryBean() {
          @Override
          protected EmbeddedCacheManager createBackingEmbeddedCacheManager() throws IOException {
            return embeddedCacheManager;
          }
        };
    return factory;
  }