tkalkirill commented on code in PR #4465: URL: https://github.com/apache/ignite-3/pull/4465#discussion_r1778519891
########## modules/metastorage/src/test/java/org/apache/ignite/internal/metastorage/server/AbstractCompactionKeyValueStorageTest.java: ########## @@ -17,186 +17,150 @@ package org.apache.ignite.internal.metastorage.server; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.ignite.internal.metastorage.dsl.Operations.noop; +import static org.apache.ignite.internal.metastorage.dsl.Operations.ops; +import static org.apache.ignite.internal.metastorage.dsl.Operations.put; +import static org.apache.ignite.internal.metastorage.dsl.Operations.remove; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import org.apache.ignite.internal.hlc.HybridClock; import org.apache.ignite.internal.hlc.HybridClockImpl; -import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.lang.ByteArray; import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.impl.CommandIdGenerator; +import org.apache.ignite.internal.metastorage.server.ExistenceCondition.Type; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** Compaction tests. */ public abstract class AbstractCompactionKeyValueStorageTest extends AbstractKeyValueStorageTest { - private final HybridClock clock = new HybridClockImpl(); - - @Test - public void testCompactionAfterLastRevision() { - byte[] key = key(0); - byte[] value1 = keyValue(0, 0); - byte[] value2 = keyValue(0, 1); + private static final byte[] FOO_KEY = fromString("foo"); - storage.put(key, value1, clock.now()); - storage.put(key, value2, clock.now()); + private static final byte[] BAR_KEY = fromString("bar"); - long lastRevision = storage.revision(); + private static final byte[] SOME_KEY = fromString("someKey"); - storage.compact(clock.now()); + private static final byte[] SOME_VALUE = fromString("someValue"); - // Latest value, must exist. - Entry entry2 = storage.get(key, lastRevision); - assertEquals(lastRevision, entry2.revision()); - assertArrayEquals(value2, entry2.value()); + private final HybridClock clock = new HybridClockImpl(); - // Previous value, must be removed due to compaction. - Entry entry1 = storage.get(key, lastRevision - 1); - assertTrue(entry1.empty()); - } + @Override + @BeforeEach + void setUp() { + super.setUp(); - @Test - public void testCompactionAfterTombstone() { - byte[] key = key(0); - byte[] value = keyValue(0, 0); + storage.putAll(List.of(FOO_KEY, BAR_KEY), List.of(SOME_VALUE, SOME_VALUE), clock.now()); + storage.put(BAR_KEY, SOME_VALUE, clock.now()); + storage.put(FOO_KEY, SOME_VALUE, clock.now()); + storage.put(SOME_KEY, SOME_VALUE, clock.now()); - storage.put(key, value, clock.now()); - storage.remove(key, clock.now()); + var fooKey = new ByteArray(FOO_KEY); + var barKey = new ByteArray(BAR_KEY); - long lastRevision = storage.revision(); + var iif = new If( + new AndCondition(new ExistenceCondition(Type.EXISTS, FOO_KEY), new ExistenceCondition(Type.EXISTS, BAR_KEY)), + new Statement(ops(put(fooKey, SOME_VALUE), remove(barKey)).yield()), + new Statement(ops(noop()).yield()) Review Comment: Probably possible, I didn’t find any examples, can you tell me how exactly to make it for storage and not for a MetastorageManager? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org