mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
CE-134 Add ChronicleMap.update(K, V) method
This commit is contained in:
@@ -226,6 +226,11 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
return map1.putMapped(key, unaryOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateResult update(K key, V value) {
|
||||
return map1.update(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UpdateTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateVanilla() {
|
||||
test(ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1).create());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReplicated() {
|
||||
test(ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1).replication((byte) 1).create());
|
||||
}
|
||||
|
||||
public static void test(ChronicleMap<Integer, CharSequence> map) {
|
||||
assertEquals(UpdateResult.INSERT, map.update(1, "1"));
|
||||
|
||||
assertEquals(UpdateResult.UPDATE, map.update(1, "2"));
|
||||
assertEquals(UpdateResult.UNCHANGED, map.update(1, "2"));
|
||||
|
||||
Assert.assertNotNull(map.remove(1));
|
||||
|
||||
assertEquals(UpdateResult.INSERT, map.update(1, "2"));
|
||||
}
|
||||
}
|
||||
@@ -179,6 +179,11 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.putMapped(key, unaryOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateResult update(K key, V value) {
|
||||
return d.update(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) throws IOException {
|
||||
d.getAll(toFile);
|
||||
|
||||
Reference in New Issue
Block a user