HCOLL-382 fixed added flag passing to MapEventListener

This commit is contained in:
leventov
2015-08-26 23:22:19 +03:00
parent 604c5f9e71
commit 5a16c8579d
3 changed files with 80 additions and 3 deletions
@@ -1158,7 +1158,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), null, false,
false);
isDeleted);
}
// for DRY (reusing replaceValueAndNotifyPut() method),
@@ -2223,7 +2223,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), null, false,
prevValueSize == 0);
false);
}
}
}
@@ -2376,7 +2376,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (eventListener != null) {
eventListener.onPut(toKey.toInstance(copies, key, keySize),
toValue.toInstance(copies, value, valueSize), prevValueInstance, remote,
false);
entryIsDeleted);
}
return resultUnused ? null : prevValue;
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2015 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.openhft.chronicle.map;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
public class MapEventListenerOnPutAddedFlagTest {
class ExpectedAddFlagChecker<K, V> extends MapEventListener<K, V> {
boolean expected;
public void setExpected(boolean expected) {
this.expected = expected;
}
@Override
public void onPut(Object key, Object newValue, @Nullable Object replacedValue,
boolean replicationEvent, boolean added) {
Assert.assertEquals(expected, added);
}
}
@Test
public void testAddedFlagVanilla() {
ExpectedAddFlagChecker<Integer, CharSequence> checker = new ExpectedAddFlagChecker<>();
test(ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.eventListener(checker)
.entries(1).create(), checker);
}
@Test
public void testAddedFlagReplicated() {
ExpectedAddFlagChecker<Integer, CharSequence> checker = new ExpectedAddFlagChecker<>();
test(ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.eventListener(checker)
.entries(1).replication((byte) 1).create(), checker);
}
private static void test(ChronicleMap<Integer, CharSequence> map,
ExpectedAddFlagChecker checker) {
checker.setExpected(true);
map.acquireUsing(1, new StringBuilder());
checker.setExpected(false);
map.put(1, "2");
checker.setExpected(false);
map.update(1, "2");
map.update(1, "3");
map.remove(1);
checker.setExpected(true);
map.update(1, "3");
map.remove(1);
map.update(1, "4");
map.remove(1);
map.put(1, "5");
}
}