Search in sources :

Example 1 with Person

use of usercodedeployment.Person in project hazelcast by hazelcast.

the class ClientUserCodeDeploymentTest method testCustomAttributeExtractor.

@Test
public void testCustomAttributeExtractor() {
    String mapName = randomMapName();
    // this attribute does not exist in the domain class
    String attributeName = "syntheticAttribute";
    ClientConfig clientConfig = new ClientConfig();
    ClientUserCodeDeploymentConfig clientUserCodeDeploymentConfig = new ClientUserCodeDeploymentConfig();
    clientUserCodeDeploymentConfig.addClass(CapitalizingFirstNameExtractor.class);
    clientUserCodeDeploymentConfig.addClass(Person.class);
    clientConfig.setUserCodeDeploymentConfig(clientUserCodeDeploymentConfig.setEnabled(true));
    Config config = createNodeConfig();
    config.getMapConfig(mapName).addAttributeConfig(new AttributeConfig(attributeName, "usercodedeployment.CapitalizingFirstNameExtractor"));
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Person> map = client.getMap(mapName);
    map.put(0, new Person("ada"));
    map.put(1, new Person("non-ada"));
    Set<Map.Entry<Integer, Person>> results = map.entrySet(equal(attributeName, "ADA"));
    assertEquals(1, results.size());
    assertEquals("ada", results.iterator().next().getValue().getName());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AttributeConfig(com.hazelcast.config.AttributeConfig) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientUserCodeDeploymentConfig(com.hazelcast.client.config.ClientUserCodeDeploymentConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) Person(usercodedeployment.Person) ClientUserCodeDeploymentConfig(com.hazelcast.client.config.ClientUserCodeDeploymentConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientUserCodeDeploymentConfig (com.hazelcast.client.config.ClientUserCodeDeploymentConfig)1 AttributeConfig (com.hazelcast.config.AttributeConfig)1 Config (com.hazelcast.config.Config)1 UserCodeDeploymentConfig (com.hazelcast.config.UserCodeDeploymentConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1 Person (usercodedeployment.Person)1