| | |
| | | @SuppressWarnings("javadoc") |
| | | public class AttrHistoricalMultipleTest extends ReplicationTestCase |
| | | { |
| | | private static enum E |
| | | { |
| | | CONFLICT(true), CONFLICT_BUT_SHOULD_NOT_BE(true), SUCCESS(false); |
| | | |
| | | private final boolean expectedConflictStatus; |
| | | |
| | | private E(boolean expectedResultForReplay) |
| | | { |
| | | this.expectedConflictStatus = expectedResultForReplay; |
| | | } |
| | | |
| | | private boolean getExpectedResult() |
| | | { |
| | | return this.expectedConflictStatus; |
| | | } |
| | | } |
| | | |
| | | private static final String ATTRIBUTE_NAME = "description"; |
| | | private static final boolean CONFLICT = true; |
| | | private static final boolean SUCCESS = false; |
| | | |
| | | private CSNGenerator csnGen = new CSNGenerator(1025, System.currentTimeMillis()); |
| | | private AttrHistoricalMultiple attrHist; |
| | |
| | | public void replay_addDeleteSameTime() throws Exception |
| | | { |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(csn, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(csn, entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperation(csn, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(csn, entry, mod, SUCCESS); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(3); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(ADD, "Y"); |
| | | replayOperation(t[2], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[2], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X", "Y"); |
| | | |
| | | mod = newModification(DELETE, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertAttributeValues(entry, "X", "Y"); |
| | | } |
| | | |
| | |
| | | replay_addDeleteNoValue(t[0], t[2]); |
| | | |
| | | mod = newModification(ADD, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(3); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperation(t[2], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[2], entry, mod, SUCCESS); |
| | | assertNoAttributeValue(entry); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(2); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertAttributeValues(entry, "X"); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(3); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[1], entry, mod, SUCCESS); |
| | | assertNoAttributeValue(entry); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[1], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | } |
| | | |
| | |
| | | public void replay_deleteNoPreviousHistory() throws Exception |
| | | { |
| | | mod = newModification(DELETE, "Y"); |
| | | replayOperationSuppressMod(csn, entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(csn, entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(2); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[1], entry, mod, SUCCESS); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | replay_addDeleteNoValue(t[0], t[2]); |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | private void replay_addDeleteNoValue(CSN tAdd, CSN tDel) throws Exception |
| | | { |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(tAdd, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(tAdd, entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(DELETE); |
| | | replayOperation(tDel, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(tDel, entry, mod, SUCCESS); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | public void replay_replace() throws Exception |
| | | { |
| | | mod = newModification(REPLACE, "X"); |
| | | replayOperation(csn, entry, mod, E.SUCCESS); |
| | | replayOperation(csn, entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | } |
| | | |
| | |
| | | CSN[] t = newCSNs(2); |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[1], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X"); |
| | | |
| | | mod = newModification(REPLACE, "Y"); |
| | | replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | replayOperation(t[0], entry, mod, SUCCESS); |
| | | assertAttributeValues(entry, "X", "Y"); |
| | | } |
| | | |
| | |
| | | replay_addDeleteNoValue(t[0], t[2]); |
| | | |
| | | mod = newModification(REPLACE, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | |
| | | return new Modification(modType, Attributes.empty(ATTRIBUTE_NAME)); |
| | | } |
| | | |
| | | private void replayOperationSuppressMod(CSN csn, Entry entry, Modification mod, E conflictStatus) |
| | | private void replayOperationSuppressMod(CSN csn, Entry entry, Modification mod, boolean shouldConflict) |
| | | throws Exception |
| | | { |
| | | Iterator<Modification> itMod = mock(Iterator.class); |
| | | replayOperation(itMod, csn, entry, mod, conflictStatus); |
| | | replayOperation(itMod, csn, entry, mod, shouldConflict); |
| | | verifyModSuppressed(itMod); |
| | | } |
| | | |
| | | private void replayOperation(CSN csn, Entry entry, Modification mod, E conflictStatus) throws Exception |
| | | private void replayOperation(CSN csn, Entry entry, Modification mod, boolean shouldConflict) throws Exception |
| | | { |
| | | Iterator<Modification> itMod = mock(Iterator.class); |
| | | replayOperation(itMod, csn, entry, mod, conflictStatus); |
| | | replayOperation(itMod, csn, entry, mod, shouldConflict); |
| | | verifyZeroInteractions(itMod); |
| | | } |
| | | |
| | | private void replayOperation(Iterator<Modification> modsIterator, CSN csn, Entry entry, Modification mod, |
| | | E conflictStatus) throws Exception |
| | | boolean shouldConflict) throws Exception |
| | | { |
| | | boolean result = attrHist.replayOperation(modsIterator, csn, entry, mod); |
| | | assertEquals(result, conflictStatus.getExpectedResult(), |
| | | "Expected " + (conflictStatus == E.CONFLICT ? "a" : "no") + " conflict when applying " + mod + " to " + entry); |
| | | if (entry != null && conflictStatus != E.CONFLICT) |
| | | assertEquals(result, shouldConflict, |
| | | "Expected " + (shouldConflict ? "a" : "no") + " conflict when applying " + mod + " to " + entry); |
| | | if (entry != null && !shouldConflict) |
| | | { |
| | | entry.applyModification(mod); |
| | | assertAttributeValues(entry, mod); |