use of com.orientechnologies.orient.core.index.OIndexKeyCursor in project orientdb by orientechnologies.
the class AutoShardingTest method testKeyCursor.
@Test
public void testKeyCursor() {
create();
final OIndexKeyCursor cursor = idx.keyCursor();
Assert.assertNotNull(cursor);
int count = 0;
for (Object entry = cursor.next(0); entry != null; entry = cursor.next(0)) {
count++;
}
Assert.assertEquals(count, ITERATIONS);
}
use of com.orientechnologies.orient.core.index.OIndexKeyCursor in project orientdb by orientechnologies.
the class ODatabaseCompare method compareIndexes.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void compareIndexes(ODocumentHelper.RIDMapper ridMapper) {
listener.onMessage("\nStarting index comparison:");
boolean ok = true;
final OIndexManager indexManagerOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndexManager>() {
public OIndexManager call(ODatabaseDocumentInternal database) {
return database.getMetadata().getIndexManager();
}
});
final OIndexManager indexManagerTwo = makeDbCall(databaseTwo, new ODbRelatedCall<OIndexManager>() {
public OIndexManager call(ODatabaseDocumentInternal database) {
return database.getMetadata().getIndexManager();
}
});
final Collection<? extends OIndex<?>> indexesOne = makeDbCall(databaseOne, new ODbRelatedCall<Collection<? extends OIndex<?>>>() {
public Collection<? extends OIndex<?>> call(ODatabaseDocumentInternal database) {
return indexManagerOne.getIndexes();
}
});
int indexesSizeOne = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() {
public Integer call(ODatabaseDocumentInternal database) {
return indexesOne.size();
}
});
int indexesSizeTwo = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() {
public Integer call(ODatabaseDocumentInternal database) {
return indexManagerTwo.getIndexes().size();
}
});
if (exportImportHashTable != null)
indexesSizeTwo--;
if (indexesSizeOne != indexesSizeTwo) {
ok = false;
listener.onMessage("\n- ERR: Amount of indexes are different.");
listener.onMessage("\n--- DB1: " + indexesSizeOne);
listener.onMessage("\n--- DB2: " + indexesSizeTwo);
listener.onMessage("\n");
++differences;
}
final Iterator<? extends OIndex<?>> iteratorOne = makeDbCall(databaseOne, new ODbRelatedCall<Iterator<? extends OIndex<?>>>() {
public Iterator<? extends OIndex<?>> call(ODatabaseDocumentInternal database) {
return indexesOne.iterator();
}
});
while (makeDbCall(databaseOne, new ODbRelatedCall<Boolean>() {
public Boolean call(ODatabaseDocumentInternal database) {
return iteratorOne.hasNext();
}
})) {
final OIndex indexOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndex<?>>() {
public OIndex<?> call(ODatabaseDocumentInternal database) {
return iteratorOne.next();
}
});
final OIndex<?> indexTwo = makeDbCall(databaseTwo, new ODbRelatedCall<OIndex<?>>() {
public OIndex<?> call(ODatabaseDocumentInternal database) {
return indexManagerTwo.getIndex(indexOne.getName());
}
});
if (indexTwo == null) {
ok = false;
listener.onMessage("\n- ERR: Index " + indexOne.getName() + " is absent in DB2.");
++differences;
continue;
}
if (!indexOne.getType().equals(indexTwo.getType())) {
ok = false;
listener.onMessage("\n- ERR: Index types for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getType());
listener.onMessage("\n--- DB2: " + indexTwo.getType());
listener.onMessage("\n");
++differences;
continue;
}
if (!indexOne.getClusters().equals(indexTwo.getClusters())) {
ok = false;
listener.onMessage("\n- ERR: Clusters to index for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getClusters());
listener.onMessage("\n--- DB2: " + indexTwo.getClusters());
listener.onMessage("\n");
++differences;
continue;
}
if (indexOne.getDefinition() == null && indexTwo.getDefinition() != null) {
ok = false;
listener.onMessage("\n- ERR: Index definition for index " + indexOne.getName() + " for DB2 is not null.");
++differences;
continue;
} else if (indexOne.getDefinition() != null && indexTwo.getDefinition() == null) {
ok = false;
listener.onMessage("\n- ERR: Index definition for index " + indexOne.getName() + " for DB2 is null.");
++differences;
continue;
} else if (indexOne.getDefinition() != null && !indexOne.getDefinition().equals(indexTwo.getDefinition())) {
ok = false;
listener.onMessage("\n- ERR: Index definitions for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getDefinition());
listener.onMessage("\n--- DB2: " + indexTwo.getDefinition());
listener.onMessage("\n");
++differences;
continue;
}
final long indexOneSize = makeDbCall(databaseOne, new ODbRelatedCall<Long>() {
public Long call(ODatabaseDocumentInternal database) {
return indexOne.getSize();
}
});
final long indexTwoSize = makeDbCall(databaseTwo, new ODbRelatedCall<Long>() {
public Long call(ODatabaseDocumentInternal database) {
return indexTwo.getSize();
}
});
if (indexOneSize != indexTwoSize) {
ok = false;
listener.onMessage("\n- ERR: Amount of entries for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOneSize);
listener.onMessage("\n--- DB2: " + indexTwoSize);
listener.onMessage("\n");
++differences;
}
if (compareIndexMetadata) {
final ODocument metadataOne = indexOne.getMetadata();
final ODocument metadataTwo = indexTwo.getMetadata();
if (metadataOne == null && metadataTwo != null) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 is null but for DB2 is not.");
listener.onMessage("\n");
++differences;
} else if (metadataOne != null && metadataTwo == null) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 is not null but for DB2 is null.");
listener.onMessage("\n");
++differences;
} else if (metadataOne != null && metadataTwo != null && !ODocumentHelper.hasSameContentOf(metadataOne, databaseOne, metadataTwo, databaseTwo, ridMapper)) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 and for DB2 are different.");
makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
listener.onMessage("\n--- M1: " + metadataOne);
return null;
}
});
makeDbCall(databaseTwo, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
listener.onMessage("\n--- M2: " + metadataTwo);
return null;
}
});
listener.onMessage("\n");
++differences;
}
}
if (((compareEntriesForAutomaticIndexes && !indexOne.getType().equals("DICTIONARY")) || !indexOne.isAutomatic())) {
final OIndexKeyCursor indexKeyCursorOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndexKeyCursor>() {
public OIndexKeyCursor call(ODatabaseDocumentInternal database) {
return indexOne.keyCursor();
}
});
Object key = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
return indexKeyCursorOne.next(-1);
}
});
while (key != null) {
final Object indexKey = key;
Object indexOneValue = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
public Object call(ODatabaseDocumentInternal database) {
return indexOne.get(indexKey);
}
});
final Object indexTwoValue = makeDbCall(databaseTwo, new ODbRelatedCall<Object>() {
public Object call(ODatabaseDocumentInternal database) {
return indexTwo.get(indexKey);
}
});
if (indexTwoValue == null) {
ok = false;
listener.onMessage("\n- ERR: Entry with key " + key + " is absent in index " + indexOne.getName() + " for DB2.");
++differences;
} else if (indexOneValue instanceof Set && indexTwoValue instanceof Set) {
final Set<Object> indexOneValueSet = (Set<Object>) indexOneValue;
final Set<Object> indexTwoValueSet = (Set<Object>) indexTwoValue;
if (!ODocumentHelper.compareSets(databaseOne, indexOneValueSet, databaseTwo, indexTwoValueSet, ridMapper)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
} else if (indexOneValue instanceof ORID && indexTwoValue instanceof ORID) {
if (ridMapper != null && ((ORID) indexOneValue).isPersistent()) {
OIdentifiable identifiable = ridMapper.map((ORID) indexOneValue);
if (identifiable != null)
indexOneValue = identifiable.getIdentity();
}
if (!indexOneValue.equals(indexTwoValue)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
} else if (!indexOneValue.equals(indexTwoValue)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
key = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
return indexKeyCursorOne.next(-1);
}
});
}
}
}
if (ok)
listener.onMessage("OK");
}
Aggregations