Search in sources :

Example 56 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class MergePolicySerializationTest method testIssue2665.

@Test
public void testIssue2665() {
    String name = randomString();
    String serviceName = "hz:impl:mapService";
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, MyObject> map = instance.getMap(name);
    MyObject myObjectExisting = new MyObject();
    map.put("key", myObjectExisting);
    NodeEngineImpl nodeEngine = HazelcastTestSupport.getNode(instance).getNodeEngine();
    MapService mapService = nodeEngine.getService(serviceName);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    int partitionId = nodeEngine.getPartitionService().getPartitionId("key");
    Data dataKey = mapServiceContext.toData("key");
    RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.class.getName());
    EntryView<String, MyObject> mergingEntryView = new SimpleEntryView<String, MyObject>("key", new MyObject());
    recordStore.merge(dataKey, mergingEntryView, mergePolicy);
    int deSerializedCount = MyObject.deserializedCount;
    assertEquals(0, deSerializedCount);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) MapService(com.hazelcast.map.impl.MapService) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 57 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class MapPutAllWrongTargetForPartitionTest method testPutAllPerMemberOperation.

/**
     * Tests that all entries and backups of a {@link PutAllPartitionAwareOperationFactory} are sent to the correct members.
     * <p/>
     * The test creates a cluster with a single partition per member and invokes {@link PutAllPartitionAwareOperationFactory}
     * which contains a single entry for every partition in the cluster. So just a single entry is for the member the factory
     * is executed on.
     * <p/>
     * After the operation is invoked we assert that each member owns one entry of the map and that all backups have been written.
     */
private void testPutAllPerMemberOperation(final int entriesPerPartition) throws Exception {
    final int expectedEntryCount = INSTANCE_COUNT * entriesPerPartition;
    final String mapName = randomMapName();
    HazelcastInstance hz = instances[0];
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    SerializationService serializationService = nodeEngine.getSerializationService();
    // create a PutAllPerMemberOperation with entries for all partitions
    PartitionAwareOperationFactory factory = createPutAllOperationFactory(entriesPerPartition, mapName, hz, serializationService);
    // invoke the operation on a random remote target
    InternalOperationService operationService = nodeEngine.getOperationService();
    operationService.invokeOnPartitions(MapService.SERVICE_NAME, factory, factory.getPartitions());
    // assert that all entries have been written
    IMap<String, String> map = hz.getMap(mapName);
    assertEquals(format("Expected %d entries in the map", expectedEntryCount), expectedEntryCount, map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        assertEquals("Expected that key and value are the same", entry.getKey(), entry.getValue());
    }
    // assert that each member owns entriesPerPartition entries of the map and that all backups have been written
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            int totalBackups = 0;
            for (int i = 0; i < INSTANCE_COUNT; i++) {
                IMap map = instances[i].getMap(mapName);
                assertEquals(format("Each member should own %d entries of the map", entriesPerPartition), entriesPerPartition, map.getLocalMapStats().getOwnedEntryCount());
                totalBackups += map.getLocalMapStats().getBackupEntryCount();
            }
            assertEquals(format("Expected to find %d backups in the cluster", expectedEntryCount), expectedEntryCount, totalBackups);
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) IMap(com.hazelcast.core.IMap) PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PutAllPartitionAwareOperationFactory(com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Example 58 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class TimedMemberStateTest method testReplicatedMapGetStats.

@Test
public void testReplicatedMapGetStats() {
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    hz.getReplicatedMap("replicatedMap");
    ReplicatedMapService replicatedMapService = nodeEngine.getService(ReplicatedMapService.SERVICE_NAME);
    assertNotNull(replicatedMapService.getStats().get("replicatedMap"));
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 59 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class OperationFailureTest method onFailure_shouldBeCalled_whenOperationIsRejected.

@Test
public void onFailure_shouldBeCalled_whenOperationIsRejected() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz = factory.newHazelcastInstance();
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    FailingOperation op = new FailingOperation(new CountDownLatch(1));
    op.setPartitionId(1).setReplicaIndex(1);
    nodeEngine.getOperationService().execute(op);
    assertOpenEventually(op.latch);
    assertInstanceOf(WrongTargetException.class, op.failure);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 60 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class ServiceManagerImplTest method setup.

@Before
public void setup() {
    Config config = new Config();
    ServiceConfig serviceConfig = new ServiceConfig().setClassName(FooService.class.getName()).setEnabled(true).setName("fooService");
    config.getServicesConfig().addServiceConfig(serviceConfig);
    HazelcastInstance hz = createHazelcastInstance(config);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    serviceManager = (ServiceManagerImpl) nodeEngine.getServiceManager();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) Before(org.junit.Before)

Aggregations

NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)112 HazelcastInstance (com.hazelcast.core.HazelcastInstance)39 Test (org.junit.Test)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)31 QuickTest (com.hazelcast.test.annotation.QuickTest)31 Node (com.hazelcast.instance.Node)21 MapService (com.hazelcast.map.impl.MapService)20 Config (com.hazelcast.config.Config)19 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)16 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)14 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)14 ILogger (com.hazelcast.logging.ILogger)11 AssertTask (com.hazelcast.test.AssertTask)11 Invalidator (com.hazelcast.internal.nearcache.impl.invalidation.Invalidator)10 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)10 Address (com.hazelcast.nio.Address)10 Data (com.hazelcast.nio.serialization.Data)10 Before (org.junit.Before)10 Operation (com.hazelcast.spi.Operation)9