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

The following examples show how to use org.infinispan.client.hotrod.configuration.NearCacheMode. 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: InfinispanClientProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
BeanContainerListenerBuildItem build(InfinispanRecorder recorder, InfinispanPropertiesBuildItem builderBuildItem) {
    Properties properties = builderBuildItem.getProperties();
    InfinispanClientBuildTimeConfig conf = infinispanClient;
    if (log.isDebugEnabled()) {
        log.debugf("Applying micro profile configuration: %s", conf);
    }
    int maxEntries = conf.nearCacheMaxEntries;
    // Only write the entries if it is a valid number and it isn't already configured
    if (maxEntries > 0 && !properties.containsKey(ConfigurationProperties.NEAR_CACHE_MODE)) {
        // This is already empty so no need for putIfAbsent
        properties.put(ConfigurationProperties.NEAR_CACHE_MODE, NearCacheMode.INVALIDATED.toString());
        properties.putIfAbsent(ConfigurationProperties.NEAR_CACHE_MAX_ENTRIES, maxEntries);
    }

    return new BeanContainerListenerBuildItem(recorder.configureInfinispan(properties));
}
 
Example #2
Source File: InfinispanNearCache.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
   // Create a client configuration connecting to a local server
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT);
   builder.nearCache().mode(NearCacheMode.INVALIDATED).maxEntries(20).cacheNamePattern("near-.*");

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

   // Create one remote cache with near caching disabled and one with near caching enabled
   RemoteCache<Integer, String> numbers = cacheManager.administration().getOrCreateCache("numbers", DefaultTemplate.DIST_SYNC);
   RemoteCache<Integer, String> nearNumbers = cacheManager.administration().getOrCreateCache("near-numbers", DefaultTemplate.DIST_SYNC);

   for (int i = 1; i<= 20; i++) {
      numbers.put(i, String.valueOf(i));
      nearNumbers.put(i, String.valueOf(i));
   }

   // Read both caches data
   readCache(numbers);
   readCache(nearNumbers);

   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
Example #3
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 #4
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");
}