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);
}
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);
}
}
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));
}
}
}
}
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;
}
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));
}
}
}
});
}
}
Aggregations