Search in sources :

Example 1 with DataSource

use of org.apache.ignite.cache.store.cassandra.datasource.DataSource in project ignite by apache.

the class IgnitePersistentStoreTest method igniteConfig.

/**
 */
private IgniteConfiguration igniteConfig() throws IOException {
    URL url = getClass().getClassLoader().getResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml");
    String persistence = U.readFileToString(url.getFile(), "UTF-8");
    KeyValuePersistenceSettings persistenceSettings = new KeyValuePersistenceSettings(persistence);
    DataSource dataSource = new DataSource();
    dataSource.setContactPoints(CassandraHelper.getContactPointsArray());
    dataSource.setCredentials(new CassandraAdminCredentials());
    dataSource.setLoadBalancingPolicy(new RoundRobinPolicy());
    CassandraCacheStoreFactory<String, Person> storeFactory = new CassandraCacheStoreFactory<>();
    storeFactory.setDataSource(dataSource);
    storeFactory.setPersistenceSettings(persistenceSettings);
    CacheConfiguration<String, Person> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("cache1");
    cacheConfiguration.setReadThrough(true);
    cacheConfiguration.setWriteThrough(true);
    cacheConfiguration.setCacheStoreFactory(storeFactory);
    IgniteConfiguration config = new IgniteConfiguration();
    config.setCacheConfiguration(cacheConfiguration);
    return config;
}
Also used : CassandraCacheStoreFactory(org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) KeyValuePersistenceSettings(org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Person(org.apache.ignite.tests.pojos.Person) URL(java.net.URL) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DataSource(org.apache.ignite.cache.store.cassandra.datasource.DataSource) CassandraAdminCredentials(org.apache.ignite.tests.utils.CassandraAdminCredentials) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy)

Example 2 with DataSource

use of org.apache.ignite.cache.store.cassandra.datasource.DataSource in project ignite by apache.

the class IgnitePersistentStorePrimitiveTest method igniteConfig.

/**
 */
private IgniteConfiguration igniteConfig() throws IOException {
    URL url = getClass().getClassLoader().getResource("org/apache/ignite/tests/persistence/blob/persistence-settings-1.xml");
    String persistence = U.readFileToString(url.getFile(), "UTF-8");
    KeyValuePersistenceSettings persistenceSettings = new KeyValuePersistenceSettings(persistence);
    DataSource dataSource = new DataSource();
    dataSource.setContactPoints(CassandraHelper.getContactPointsArray());
    dataSource.setCredentials(new CassandraAdminCredentials());
    dataSource.setLoadBalancingPolicy(new RoundRobinPolicy());
    CassandraCacheStoreFactory<Long, Long> storeFactory = new CassandraCacheStoreFactory<>();
    storeFactory.setDataSource(dataSource);
    storeFactory.setPersistenceSettings(persistenceSettings);
    CacheConfiguration<Long, Long> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("cache1");
    cacheConfiguration.setReadThrough(true);
    cacheConfiguration.setWriteThrough(true);
    cacheConfiguration.setCacheStoreFactory(storeFactory);
    IgniteConfiguration config = new IgniteConfiguration();
    config.setCacheConfiguration(cacheConfiguration);
    return config;
}
Also used : CassandraCacheStoreFactory(org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) KeyValuePersistenceSettings(org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings) URL(java.net.URL) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DataSource(org.apache.ignite.cache.store.cassandra.datasource.DataSource) CassandraAdminCredentials(org.apache.ignite.tests.utils.CassandraAdminCredentials) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy)

Example 3 with DataSource

use of org.apache.ignite.cache.store.cassandra.datasource.DataSource in project ignite by apache.

the class DatasourceSerializationTest method serializationTest.

/**
 * Serialization test.
 */
@Test
public void serializationTest() {
    DataSource src = new DataSource();
    Credentials cred = new CassandraAdminCredentials();
    String[] points = new String[] { "127.0.0.1", "10.0.0.2", "10.0.0.3" };
    LoadBalancingPolicy plc = new MyLoadBalancingPolicy();
    src.setCredentials(cred);
    src.setContactPoints(points);
    src.setReadConsistency("ONE");
    src.setWriteConsistency("QUORUM");
    src.setLoadBalancingPolicy(plc);
    JavaSerializer serializer = new JavaSerializer();
    ByteBuffer buff = serializer.serialize(src);
    DataSource _src = (DataSource) serializer.deserialize(buff);
    Credentials _cred = (Credentials) getFieldValue(_src, "creds");
    List<InetAddress> _points = (List<InetAddress>) getFieldValue(_src, "contactPoints");
    ConsistencyLevel _readCons = (ConsistencyLevel) getFieldValue(_src, "readConsistency");
    ConsistencyLevel _writeCons = (ConsistencyLevel) getFieldValue(_src, "writeConsistency");
    LoadBalancingPolicy _plc = (LoadBalancingPolicy) getFieldValue(_src, "loadBalancingPlc");
    assertTrue("Incorrectly serialized/deserialized credentials for Cassandra DataSource", cred.getPassword().equals(_cred.getPassword()) && cred.getUser().equals(_cred.getUser()));
    assertTrue("Incorrectly serialized/deserialized contact points for Cassandra DataSource", "/127.0.0.1".equals(_points.get(0).toString()) && "/10.0.0.2".equals(_points.get(1).toString()) && "/10.0.0.3".equals(_points.get(2).toString()));
    assertTrue("Incorrectly serialized/deserialized consistency levels for Cassandra DataSource", ConsistencyLevel.ONE == _readCons && ConsistencyLevel.QUORUM == _writeCons);
    assertTrue("Incorrectly serialized/deserialized load balancing policy for Cassandra DataSource", _plc instanceof MyLoadBalancingPolicy);
}
Also used : JavaSerializer(org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer) ByteBuffer(java.nio.ByteBuffer) DataSource(org.apache.ignite.cache.store.cassandra.datasource.DataSource) CassandraAdminCredentials(org.apache.ignite.tests.utils.CassandraAdminCredentials) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) LoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy) List(java.util.List) InetAddress(java.net.InetAddress) CassandraAdminCredentials(org.apache.ignite.tests.utils.CassandraAdminCredentials) Credentials(org.apache.ignite.cache.store.cassandra.datasource.Credentials) Test(org.junit.Test)

Aggregations

DataSource (org.apache.ignite.cache.store.cassandra.datasource.DataSource)3 CassandraAdminCredentials (org.apache.ignite.tests.utils.CassandraAdminCredentials)3 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)2 URL (java.net.URL)2 CassandraCacheStoreFactory (org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory)2 KeyValuePersistenceSettings (org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Credentials (org.apache.ignite.cache.store.cassandra.datasource.Credentials)1 JavaSerializer (org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer)1 Person (org.apache.ignite.tests.pojos.Person)1 SimplePerson (org.apache.ignite.tests.pojos.SimplePerson)1 Test (org.junit.Test)1