- better error message

- code readability with extracted method
This commit is contained in:
Maxim.Mossienko
2016-02-25 13:34:05 +01:00
parent 1b33820b2a
commit 007e54fc74
@@ -398,30 +398,7 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
if (data == null) {
data = content != null ? myIndexer.map(content) : Collections.<Key, Value>emptyMap();
if (DebugAssertions.EXTRA_SANITY_CHECKS) {
for(Map.Entry<Key, Value> e: data.entrySet()) {
final Value value = e.getValue();
if (!(Comparing.equal(value, value) && (value == null || value.hashCode() == value.hashCode()))) {
LOG.error("Index %s violates equals / hashCode contract for Value parameter", myIndexId.toString());
}
if (myValueExternalizer != null) {
try {
final BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(out);
myValueExternalizer.save(outputStream, value);
outputStream.close();
final Value deserializedValue =
myValueExternalizer.read(new DataInputStream(new UnsyncByteArrayInputStream(out.getInternalBuffer(), 0, out.size())));
if (!(Comparing.equal(value, deserializedValue) && (value == null || value.hashCode() == deserializedValue.hashCode()))) {
LOG.error("Index %s violates equals / hashCode contract for Value parameter", myIndexId.toString());
}
} catch (IOException ex) {
LOG.error(ex);
}
}
}
checkValuesHaveProperEqualsAndHashCode(data);
}
}
@@ -576,6 +553,32 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
};
}
private void checkValuesHaveProperEqualsAndHashCode(Map<Key, Value> data) {
for(Map.Entry<Key, Value> e: data.entrySet()) {
final Value value = e.getValue();
if (!(Comparing.equal(value, value) && (value == null || value.hashCode() == value.hashCode()))) {
LOG.error("Index " + myIndexId.toString() + " violates equals / hashCode contract for Value parameter");
}
if (myValueExternalizer != null) {
try {
final BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(out);
myValueExternalizer.save(outputStream, value);
outputStream.close();
final Value deserializedValue =
myValueExternalizer.read(new DataInputStream(new UnsyncByteArrayInputStream(out.getInternalBuffer(), 0, out.size())));
if (!(Comparing.equal(value, deserializedValue) && (value == null || value.hashCode() == deserializedValue.hashCode()))) {
LOG.error("Index " + myIndexId.toString() + " violates equals / hashCode contract for Value parameter");
}
} catch (IOException ex) {
LOG.error(ex);
}
}
}
}
private StringBuilder buildDiff(Map<Key, Value> data, Map<Key, Value> contentData) {
StringBuilder moreInfo = new StringBuilder();
if (contentData.size() != data.size()) {