Search in sources :

Example 16 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class CacheReplicationOperationTest method sendsConfigObjectOverWire.

@Test
public void sendsConfigObjectOverWire() throws Exception {
    // new config
    CacheConfig config = new CacheConfig("test-cache");
    // add config to cache service
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(createHazelcastInstance());
    CacheService cacheService = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
    cacheService.putCacheConfigIfAbsent(config);
    CachePartitionSegment segment = new CachePartitionSegment(cacheService, 0);
    segment.getOrCreateRecordStore(config.getNameWithPrefix());
    Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(0);
    assertEquals(1, namespaces.size());
    // create operation
    CacheReplicationOperation operation = new CacheReplicationOperation();
    operation.prepare(segment, namespaces, 0);
    // serialize & deserialize operation
    Data data = nodeEngineImpl.toData(operation);
    CacheReplicationOperation cacheReplicationOperation = (CacheReplicationOperation) nodeEngineImpl.toObject(data);
    // new operation instance should have previously added config.
    assertContains(cacheReplicationOperation.getConfigs(), config);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Data(com.hazelcast.internal.serialization.Data) CacheConfig(com.hazelcast.config.CacheConfig) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class PartitionReplicaVersionsCorrectnessStressTest method verifyReplicaVersions.

private void verifyReplicaVersions(PartitionReplicaVersionsView initialReplicaVersions, PartitionReplicaVersionsView replicaVersions, int minSurvivingReplicaIndex, String message) {
    Set<String> lostMapNames = new HashSet<String>();
    for (int i = 0; i < minSurvivingReplicaIndex; i++) {
        lostMapNames.add(getIthMapName(i));
    }
    for (ServiceNamespace namespace : initialReplicaVersions.getNamespaces()) {
        if (replicaVersions.getVersions(namespace) == null) {
            if (namespace instanceof DistributedObjectNamespace) {
                String objectName = ((DistributedObjectNamespace) namespace).getObjectName();
                assertThat(objectName, Matchers.isIn(lostMapNames));
                continue;
            } else {
                fail("No replica version found for " + namespace);
            }
        }
        verifyReplicaVersions(initialReplicaVersions.getVersions(namespace), replicaVersions.getVersions(namespace), minSurvivingReplicaIndex, message);
    }
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) HashSet(java.util.HashSet)

Example 18 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class PartitionCorrectnessTestSupport method assertReplicaVersionsAndBackupValues.

private <N> void assertReplicaVersionsAndBackupValues(int actualBackupCount, TestAbstractMigrationAwareService<N> service, Node node, InternalPartition[] partitions, N name, boolean allowDirty) {
    Address thisAddress = node.getThisAddress();
    ServiceNamespace namespace = service.getNamespace(name);
    for (InternalPartition partition : partitions) {
        if (partition.isLocal()) {
            int partitionId = partition.getPartitionId();
            long[] replicaVersions = getPartitionReplicaVersionsView(node, partitionId).getVersions(namespace);
            for (int replica = 1; replica <= actualBackupCount; replica++) {
                Address address = partition.getReplicaAddress(replica);
                assertNotNull("On " + thisAddress + ", Replica: " + replica + " is not found in " + partition, address);
                HazelcastInstance backupInstance = factory.getInstance(address);
                assertNotNull("Instance for " + address + " is not found! -> " + partition, backupInstance);
                Node backupNode = getNode(backupInstance);
                assertNotNull(backupNode);
                PartitionReplicaVersionsView backupReplicaVersionsView = getPartitionReplicaVersionsView(backupNode, partitionId);
                long[] backupReplicaVersions = backupReplicaVersionsView.getVersions(namespace);
                assertNotNull(namespace + " replica versions are null on " + backupNode.address + ", partitionId: " + partitionId + ", replicaIndex: " + replica, backupReplicaVersions);
                for (int i = replica - 1; i < actualBackupCount; i++) {
                    assertEquals("Replica version mismatch! Owner: " + thisAddress + ", Backup: " + address + ", Partition: " + partition + ", Replica: " + (i + 1) + " owner versions: " + Arrays.toString(replicaVersions) + " backup versions: " + Arrays.toString(backupReplicaVersions), replicaVersions[i], backupReplicaVersions[i]);
                }
                if (!allowDirty) {
                    assertFalse("Backup replica is dirty! Owner: " + thisAddress + ", Backup: " + address + ", Partition: " + partition, backupReplicaVersionsView.isDirty(namespace));
                }
                TestAbstractMigrationAwareService backupService = getService(backupInstance, service.getServiceName());
                assertEquals("Wrong data! Partition: " + partitionId + ", replica: " + replica + " on " + address + " has stale value! " + Arrays.toString(backupReplicaVersions), service.get(name, partitionId), backupService.get(name, partitionId));
            }
        }
    }
}
Also used : TestAbstractMigrationAwareService(com.hazelcast.internal.partition.service.TestAbstractMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) TestPartitionUtils.getPartitionReplicaVersionsView(com.hazelcast.internal.partition.TestPartitionUtils.getPartitionReplicaVersionsView)

Example 19 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class PartitionReplicaVersionsView method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (!(o instanceof PartitionReplicaVersionsView)) {
        return false;
    }
    PartitionReplicaVersionsView that = (PartitionReplicaVersionsView) o;
    long[] emptyVersions = new long[InternalPartition.MAX_BACKUP_COUNT];
    Collection<ServiceNamespace> namespaces = new HashSet<ServiceNamespace>(versions.keySet());
    namespaces.addAll(that.versions.keySet());
    for (ServiceNamespace ns : namespaces) {
        long[] thisVersions = getVersions(ns);
        long[] thatVersions = that.getVersions(ns);
        if (thisVersions == null) {
            thisVersions = emptyVersions;
        }
        if (thatVersions == null) {
            thatVersions = emptyVersions;
        }
        if (!Arrays.equals(thisVersions, thatVersions)) {
            return false;
        }
    }
    if (dirtyNamespaces.size() != that.dirtyNamespaces.size()) {
        return false;
    }
    for (ServiceNamespace ns : dirtyNamespaces) {
        if (!that.isDirty(ns)) {
            return false;
        }
    }
    return true;
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) HashSet(java.util.HashSet)

Example 20 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class AntiEntropyCleanupTest method testCleanup.

@Test
public void testCleanup() {
    Config config = new Config().setProperty(PARTITION_BACKUP_SYNC_INTERVAL.getName(), "1");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    HazelcastInstance[] instances = factory.newInstances(config, nodeCount);
    warmUpPartitions(instances);
    String mapName = randomMapName();
    HazelcastInstance instance1 = instances[0];
    for (int partitionId = 0; partitionId < getPartitionService(instance1).getPartitionCount(); partitionId++) {
        String key = generateKeyForPartition(instance1, partitionId);
        instance1.getMap(mapName).put(key, key);
    }
    instance1.getMap(mapName).destroy();
    for (final HazelcastInstance instance : instances) {
        final InternalPartitionService partitionService = getPartitionService(instance);
        final PartitionReplicaVersionManager replicaVersionManager = partitionService.getPartitionReplicaVersionManager();
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
                    for (ServiceNamespace namespace : replicaVersionManager.getNamespaces(partitionId)) {
                        assertFalse(namespace.getServiceName().equals(MapService.SERVICE_NAME));
                    }
                }
            }
        });
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)40 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)11 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)8 HashMap (java.util.HashMap)7 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)6 ILogger (com.hazelcast.logging.ILogger)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)4 PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)4 HashSet (java.util.HashSet)4 Address (com.hazelcast.cluster.Address)3 ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2 CacheService (com.hazelcast.cache.impl.CacheService)2 CacheConfig (com.hazelcast.config.CacheConfig)2