use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.
the class PartitionCorrectnessTestSupport method assertSizeAndData.
private void assertSizeAndData(boolean allowDirty) throws InterruptedException {
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
final int actualBackupCount = Math.min(backupCount, instances.size() - 1);
final int expectedSize = partitionCount * (actualBackupCount + 1);
int total = 0;
for (HazelcastInstance hz : instances) {
TestMigrationAwareService service = getService(hz);
total += service.size();
Node node = getNode(hz);
InternalPartitionService partitionService = node.getPartitionService();
InternalPartition[] partitions = partitionService.getInternalPartitions();
Address thisAddress = node.getThisAddress();
// find leaks
assertNoLeakingData(service, partitions, thisAddress);
// find missing
assertNoMissingData(service, partitions, thisAddress);
// check values
assertPartitionVersionsAndBackupValues(actualBackupCount, service, node, partitions, allowDirty);
assertMigrationEvents(service, thisAddress);
}
assertEquals("Missing data!", expectedSize, total);
}
use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method assertReplicaVersionsAndServiceData.
private void assertReplicaVersionsAndServiceData(String msg, Address address, int partitionId, int replicaIndex) throws Exception {
TestMigrationAwareService service = getService(address);
boolean shouldContainData = replicaIndex != -1 && replicaIndex <= BACKUP_COUNT;
assertEquals(msg, shouldContainData, service.contains(partitionId));
long[] replicaVersions = getReplicaVersions(factory.getInstance(address), partitionId);
msg = msg + " , ReplicaVersions: " + Arrays.toString(replicaVersions);
if (shouldContainData) {
if (replicaIndex == 0) {
assertArrayEquals(msg, replicaVersions, new long[] { 1, 1, 1, 1, 1, 1 });
} else {
for (int i = 1; i < InternalPartition.MAX_BACKUP_COUNT; i++) {
if (i < replicaIndex || i > BACKUP_COUNT) {
assertEquals(msg + " at index: " + i, 0, replicaVersions[i - 1]);
} else {
assertEquals(msg + " at index: " + i, 1, replicaVersions[i - 1]);
}
}
}
} else {
assertArrayEquals(msg, replicaVersions, new long[] { 0, 0, 0, 0, 0, 0 });
}
}
use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method setup.
@Before
public void setup() throws Exception {
blockMigrationStartLatch = new CountDownLatch(1);
factory = createHazelcastInstanceFactory(NODE_COUNT);
instances = factory.newInstances(createConfig(), NODE_COUNT);
warmUpPartitions(instances);
waitAllForSafeState(instances);
InternalOperationService operationService = getOperationService(instances[0]);
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
InternalPartitionService partitionService = getPartitionService(instances[0]);
InternalPartition partition = partitionService.getPartition(partitionId);
for (int i = 0; i <= BACKUP_COUNT; i++) {
Address replicaAddress = partition.getReplicaAddress(i);
if (replicaAddress != null) {
TestMigrationAwareService service = getService(replicaAddress);
assertNotNull(service.get(partitionId));
}
}
}
}
});
for (HazelcastInstance instance : instances) {
TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
service.clearEvents();
}
}
use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method clearReplicaIndex.
private Address clearReplicaIndex(final int partitionId, int replicaIndexToClear) {
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[0]);
InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
final Address oldReplicaOwner = partition.getReplicaAddress(replicaIndexToClear);
partition.setReplicaAddress(replicaIndexToClear, null);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(partitionService.syncPartitionRuntimeState());
}
});
HazelcastInstance oldReplicaOwnerInstance = factory.getInstance(oldReplicaOwner);
ClearReplicaRunnable op = new ClearReplicaRunnable(partitionId, getNodeEngineImpl(oldReplicaOwnerInstance));
getOperationService(oldReplicaOwnerInstance).execute(op);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
long[] replicaVersions = getReplicaVersions(factory.getInstance(oldReplicaOwner), partitionId);
assertArrayEquals(new long[InternalPartition.MAX_BACKUP_COUNT], replicaVersions);
}
});
TestMigrationAwareService migrationAwareService = getService(oldReplicaOwner);
migrationAwareService.clearPartitionReplica(partitionId);
for (HazelcastInstance instance : instances) {
TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
service.clearEvents();
}
return oldReplicaOwner;
}
use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.
the class PartitionCorrectnessTestSupport method assertPartitionVersionsAndBackupValues.
private void assertPartitionVersionsAndBackupValues(int actualBackupCount, TestMigrationAwareService service, Node node, InternalPartition[] partitions, boolean allowDirty) throws InterruptedException {
Address thisAddress = node.getThisAddress();
for (InternalPartition partition : partitions) {
if (partition.isLocal()) {
int partitionId = partition.getPartitionId();
long[] replicaVersions = getReplicaVersions(node, partitionId);
for (int replica = 1; replica <= actualBackupCount; replica++) {
Address address = partition.getReplicaAddress(replica);
assertNotNull("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();
assertNotNull("Versions null on " + backupNode.address + ", partitionId: " + partitionId, 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());
}
TestMigrationAwareService backupService = getService(backupInstance);
assertEquals("Wrong data! Partition: " + partitionId + ", replica: " + replica + " on " + address + " has stale value! " + Arrays.toString(backupReplicaVersions), service.get(partitionId), backupService.get(partitionId));
}
}
}
}
Aggregations