org.infinispan.client.hotrod.configuration.TransactionMode Java Examples

The following examples show how to use org.infinispan.client.hotrod.configuration.TransactionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfinispanConfiguration.java    From teiid-spring-boot with Apache License 2.0 4 votes vote down vote up
public void setTransactionMode(TransactionMode transactionMode) {
    this.transactionMode = transactionMode;
}
 
Example #2
Source File: CustomPropertiesTest.java    From infinispan-spring-boot with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultClient() throws Exception {
   //when
   Configuration configuration = remoteCacheManager.getConfiguration();
   String hostObtainedFromPropertiesFile = configuration.servers().get(0).host();
   int portObtainedFromPropertiesFile = configuration.servers().get(0).port();

   // Connection
   assertThat(hostObtainedFromPropertiesFile).isEqualTo("127.0.0.1");
   assertThat(portObtainedFromPropertiesFile).isEqualTo(6667);
   assertThat(configuration.tcpNoDelay()).isFalse();
   assertThat(configuration.tcpKeepAlive()).isTrue();
   assertThat(configuration.clientIntelligence()).isEqualTo(ClientIntelligence.TOPOLOGY_AWARE);
   assertThat(configuration.socketTimeout()).isEqualTo(3000);
   assertThat(configuration.connectionTimeout()).isEqualTo(5000);
   assertThat(configuration.maxRetries()).isEqualTo(42);
   assertThat(configuration.batchSize()).isEqualTo(90);
   assertThat(configuration.version()).isEqualTo(ProtocolVersion.PROTOCOL_VERSION_28);

   // Connection pool properties
   assertThat(configuration.connectionPool().maxActive()).isEqualTo(91);
   assertThat(configuration.connectionPool().exhaustedAction()).isEqualTo(ExhaustedAction.EXCEPTION);
   assertThat(configuration.connectionPool().maxWait()).isEqualTo(20001);
   assertThat(configuration.connectionPool().minIdle()).isEqualTo(1001);
   assertThat(configuration.connectionPool().minEvictableIdleTime()).isEqualTo(9001);
   assertThat(configuration.connectionPool().maxPendingRequests()).isEqualTo(846);

   // Thread pool properties
   assertThat(configuration.asyncExecutorFactory().factoryClass()).isEqualTo(DefaultAsyncExecutorFactory.class);
   // TODO: how to assert thread pool size ? default_executor_factory.pool_size

   // Marshalling properties
   assertThat(configuration.marshallerClass()).isEqualTo(JavaSerializationMarshaller.class);
   assertThat(configuration.keySizeEstimate()).isEqualTo(123456);
   assertThat(configuration.valueSizeEstimate()).isEqualTo(789012);
   assertThat(configuration.forceReturnValues()).isTrue();
   assertThat(configuration.serialWhitelist()).contains("SERIAL-KILLER");
   // TODO: Consistent Hash Impl ??
   //assertThat(configuration.consistentHashImpl().getClass().toString()).isEqualTo("");

   // Encryption properties
   assertThat(configuration.security().ssl().enabled()).isTrue();
   assertThat(configuration.security().ssl().keyStoreFileName()).isEqualTo("keyStoreFile");
   assertThat(configuration.security().ssl().keyStoreType()).isEqualTo("JKS");
   assertThat(configuration.security().ssl().keyStorePassword()).hasSize(12);
   assertThat(configuration.security().ssl().keyAlias()).isEqualTo("aliasKey");
   assertThat(configuration.security().ssl().keyStoreCertificatePassword()).hasSize(9);
   assertThat(configuration.security().ssl().trustStoreFileName()).isEqualTo("trustFileName");
   assertThat(configuration.security().ssl().trustStorePath()).isNull();
   assertThat(configuration.security().ssl().trustStoreType()).isEqualTo("LOL");
   assertThat(configuration.security().ssl().trustStorePassword().length).isEqualTo(13);
   assertThat(configuration.security().ssl().sniHostName()).isEqualTo("oihost");
   assertThat(configuration.security().ssl().protocol()).isEqualTo("TLSv1.3");

   // authentication
   assertThat(configuration.security().authentication().enabled()).isTrue();
   assertThat(configuration.security().authentication().saslMechanism()).isEqualTo("DIGEST-MD5");
   assertThat(configuration.security().authentication().callbackHandler()).isInstanceOf(BasicCallbackHandler.class);
   assertThat(configuration.security().authentication().serverName()).isEqualTo("my_ela_server_name");
   BasicCallbackHandler basicCallbackHandler = (BasicCallbackHandler) configuration.security().authentication().callbackHandler();
   NameCallback nameCallback = new NameCallback("test", "test");
   PasswordCallback passwordCallback = new PasswordCallback("test", false);
   RealmCallback realmCallback = new RealmCallback("test", "test");
   basicCallbackHandler.handle(new Callback[]{nameCallback, passwordCallback, realmCallback});
   assertThat(nameCallback.getName()).isEqualTo("elaia");
   assertThat(passwordCallback.getPassword()).isEqualTo("elapass".toCharArray());
   assertThat(realmCallback.getText()).isEqualTo("elarealm");
   assertThat(configuration.security().authentication().saslProperties()).hasSize(1);
   assertThat(configuration.security().authentication().saslProperties()).containsOnlyKeys("prop1");
   assertThat(configuration.security().authentication().saslProperties()).containsValues("value1");

   // Transaction properties
   // TODO: transaction_manager_lookup??
   assertThat(configuration.transaction().transactionMode()).isEqualTo(TransactionMode.FULL_XA);
   assertThat(configuration.transaction().timeout()).isEqualTo(50001);

   // near cache
   assertThat(configuration.nearCache().mode()).isEqualTo(NearCacheMode.INVALIDATED);
   assertThat(configuration.nearCache().maxEntries()).isEqualTo(10000);
   assertThat(configuration.nearCache().cacheNamePattern().pattern()).isEqualTo("nearSuperCache*");

   // xsite
   assertThat(configuration.clusters()).hasSize(2);
   ClusterConfiguration siteA = configuration.clusters().get(0);
   ClusterConfiguration siteB = configuration.clusters().get(1);
   assertThat(siteA.getClusterName()).isEqualTo("siteA");
   assertThat(siteB.getClusterName()).isEqualTo("siteB");
   assertThat(siteA.getCluster()).extracting("host", "port").containsExactly(tuple("hostA1", 11222), tuple("hostA2", 11223));
   assertThat(siteB.getCluster()).extracting("host", "port").containsExactly(tuple("hostB1", 11224), tuple("hostB2", 11225));

   // statistics
   assertThat(configuration.statistics().enabled()).isTrue();
   assertThat(configuration.statistics().jmxEnabled()).isTrue();
   assertThat(configuration.statistics().jmxName()).isEqualTo("elaJmx");
   assertThat(configuration.statistics().jmxDomain()).isEqualTo("elaJmxDom2");
}
 
Example #3
Source File: ApplicationPropertiesTest.java    From infinispan-spring-boot with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultClient() throws Exception {
   //when
   Configuration configuration = remoteCacheManager.getConfiguration();
   String hostObtainedFromPropertiesFile = configuration.servers().get(0).host();
   int portObtainedFromPropertiesFile = configuration.servers().get(0).port();

   configuration.asyncExecutorFactory().factoryClass();

   // properties
   assertThat(hostObtainedFromPropertiesFile).isEqualTo("180.567.112.333");
   assertThat(portObtainedFromPropertiesFile).isEqualTo(6668);
   assertThat(configuration.tcpNoDelay()).isFalse();
   assertThat(configuration.tcpKeepAlive()).isTrue();
   assertThat(configuration.clientIntelligence()).isEqualTo(ClientIntelligence.TOPOLOGY_AWARE);
   assertThat(configuration.socketTimeout()).isEqualTo(500);
   assertThat(configuration.connectionTimeout()).isEqualTo(200);
   assertThat(configuration.maxRetries()).isEqualTo(30);
   assertThat(configuration.batchSize()).isEqualTo(91);
   assertThat(configuration.version()).isEqualTo(ProtocolVersion.PROTOCOL_VERSION_24);

   // pool
   assertThat(configuration.connectionPool().maxActive()).isEqualTo(90);
   assertThat(configuration.connectionPool().maxWait()).isEqualTo(20000);
   assertThat(configuration.connectionPool().minIdle()).isEqualTo(1000);
   assertThat(configuration.connectionPool().maxPendingRequests()).isEqualTo(845);
   assertThat(configuration.connectionPool().minEvictableIdleTime()).isEqualTo(9000);
   assertThat(configuration.connectionPool().exhaustedAction()).isEqualTo(ExhaustedAction.CREATE_NEW);

   // Thread pool properties
   assertThat(configuration.asyncExecutorFactory().factoryClass()).isEqualTo(DefaultAsyncExecutorFactory.class);
   // TODO: how to assert thread pool size ? default-executor-factory-pool-size

   // Marshalling properties
   assertThat(configuration.marshallerClass()).isEqualTo(JavaSerializationMarshaller.class);
   assertThat(configuration.keySizeEstimate()).isEqualTo(88889);
   assertThat(configuration.valueSizeEstimate()).isEqualTo(11112);
   assertThat(configuration.forceReturnValues()).isTrue();
   assertThat(configuration.serialWhitelist()).contains("APP-KILLER1", "APP-KILLER2");
   // TODO: Consistent Hash Impl ??
   //assertThat(configuration.consistentHashImpl().getClass().toString()).isEqualTo("");

   // Encryption properties
   assertThat(configuration.security().ssl().enabled()).isTrue();
   assertThat(configuration.security().ssl().keyStoreFileName()).isEqualTo("superKeyStoreFile");
   assertThat(configuration.security().ssl().keyStoreType()).isEqualTo("SKL");
   assertThat(configuration.security().ssl().keyStorePassword().length).isEqualTo(17);
   assertThat(configuration.security().ssl().keyAlias()).isEqualTo("superAliasKey");
   assertThat(configuration.security().ssl().keyStoreCertificatePassword()).hasSize(13);
   assertThat(configuration.security().ssl().trustStoreFileName()).isEqualTo("superTrustFileName");
   assertThat(configuration.security().ssl().trustStorePath()).isNull();
   assertThat(configuration.security().ssl().trustStoreType()).isEqualTo("CKO");
   assertThat(configuration.security().ssl().trustStorePassword().length).isEqualTo(18);
   assertThat(configuration.security().ssl().sniHostName()).isEqualTo("elahost");
   assertThat(configuration.security().ssl().protocol()).isEqualTo("TLSv1.4");

   // authentication
   assertThat(configuration.security().authentication().enabled()).isTrue();
   assertThat(configuration.security().authentication().callbackHandler().getClass()).isEqualTo(BasicCallbackHandler.class);
   assertThat(configuration.security().authentication().saslMechanism()).isEqualTo("my-sasl-mechanism");
   assertThat(configuration.security().authentication().serverName()).isEqualTo("my-server-name");
   BasicCallbackHandler basicCallbackHandler = (BasicCallbackHandler) configuration.security().authentication().callbackHandler();
   NameCallback nameCallback = new NameCallback("test", "test");
   PasswordCallback passwordCallback = new PasswordCallback("test", false);
   RealmCallback realmCallback = new RealmCallback("test", "test");
   basicCallbackHandler.handle(new Callback[]{nameCallback, passwordCallback, realmCallback});
   assertThat(nameCallback.getName()).isEqualTo("oihana");
   assertThat(passwordCallback.getPassword()).isEqualTo("oipass".toCharArray());
   assertThat(realmCallback.getText()).isEqualTo("oirealm");
   assertThat(configuration.security().authentication().saslProperties()).hasSize(2);
   assertThat(configuration.security().authentication().saslProperties()).extracting("prop1", "prop2").containsExactly("value1", "value2");

   // transactions
   assertThat(configuration.transaction().transactionMode()).isEqualTo(TransactionMode.NON_DURABLE_XA);
   assertThat(configuration.transaction().timeout()).isEqualTo(50000);

   // near cache
   assertThat(configuration.nearCache().mode()).isEqualTo(NearCacheMode.INVALIDATED);
   assertThat(configuration.nearCache().maxEntries()).isEqualTo(2000);
   assertThat(configuration.nearCache().cacheNamePattern().pattern()).isEqualTo("appCache*");

   // xsite
   assertThat(configuration.clusters()).hasSize(1);
   ClusterConfiguration site = configuration.clusters().get(0);
   assertThat(site.getCluster()).extracting("host", "port").containsExactly(tuple("hostOi1", 21222), tuple("hostOi2", 21223));

   // statistics
   assertThat(configuration.statistics().enabled()).isTrue();
   assertThat(configuration.statistics().jmxEnabled()).isTrue();
   assertThat(configuration.statistics().jmxName()).isEqualTo("oiJmx");
   assertThat(configuration.statistics().jmxDomain()).isEqualTo("oiJmxDom");
}
 
Example #4
Source File: InfinispanRemoteTx.java    From infinispan-simple-tutorials with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   // Create a configuration for a locally-running server
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer()
            .host("127.0.0.1")
            .port(ConfigurationProperties.DEFAULT_HOTROD_PORT)
          .security().authentication()
            //Add user credentials.
            .username("username")
            .password("password")
            .realm("default")
            .saslMechanism("DIGEST-MD5");

   // Configure the RemoteCacheManager to use a transactional cache as default
   // Use the simple TransactionManager in hot rod client
   builder.transaction().transactionManagerLookup(RemoteTransactionManagerLookup.getInstance());
   // The cache will be enlisted as Synchronization
   builder.transaction().transactionMode(TransactionMode.NON_XA);

   // Connect to the server
   RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());

   // Create a transactional cache in the server since there is none available by default.
   cacheManager.administration().createCache(CACHE_NAME, new XMLStringConfiguration(TEST_CACHE_XML_CONFIG));
   RemoteCache<String, String> cache = cacheManager.getCache(CACHE_NAME);

   // Obtain the transaction manager
   TransactionManager transactionManager = cache.getTransactionManager();
   // Perform some operations within a transaction and commit it
   transactionManager.begin();
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   transactionManager.commit();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Perform some operations within a transaction and roll it back
   transactionManager.begin();
   cache.put("key1", "value3");
   cache.put("key2", "value4");
   transactionManager.rollback();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}