some lombok cleanup

This commit is contained in:
2025-01-02 17:48:38 +01:00
parent 2d060d8140
commit 6540b51b5d
19 changed files with 165 additions and 202 deletions

View File

@@ -34,11 +34,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@@ -13,11 +13,6 @@
<artifactId>kleppmanntree</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>

View File

@@ -1 +0,0 @@
lombok.accessors.prefix += _

View File

@@ -1,12 +1,16 @@
package com.usatiuk.kleppmanntree;
import lombok.Getter;
public abstract class TestNodeMeta implements NodeMeta {
@Getter
private final String _name;
public TestNodeMeta(String name) {_name = name;}
@Override
public String getName() {
return _name;
}
public TestNodeMeta(String name) {
_name = name;
}
abstract public NodeMeta withName(String name);
}

View File

@@ -1,11 +1,12 @@
package com.usatiuk.kleppmanntree;
import lombok.Getter;
public class TestNodeMetaFile extends TestNodeMeta {
@Getter
private final long _inode;
public long getInode() {
return _inode;
}
public TestNodeMetaFile(String name, long inode) {
super(name);
_inode = inode;

View File

@@ -1,12 +1,8 @@
package com.usatiuk.kleppmanntree;
import lombok.Builder;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@Builder(toBuilder = true)
public record TestTreeNode(Long key, Long parent, OpMove<Long, Long, TestNodeMeta, Long> lastEffectiveOp,
TestNodeMeta meta,
Map<String, Long> children) implements TreeNode<Long, Long, TestNodeMeta, Long> {
@@ -17,21 +13,21 @@ public record TestTreeNode(Long key, Long parent, OpMove<Long, Long, TestNodeMet
@Override
public TreeNode<Long, Long, TestNodeMeta, Long> withParent(Long parent) {
return this.toBuilder().parent(parent).build();
return new TestTreeNode(key, parent, lastEffectiveOp, meta, children);
}
@Override
public TreeNode<Long, Long, TestNodeMeta, Long> withLastEffectiveOp(OpMove<Long, Long, TestNodeMeta, Long> lastEffectiveOp) {
return this.toBuilder().lastEffectiveOp(lastEffectiveOp).build();
return new TestTreeNode(key, parent, lastEffectiveOp, meta, children);
}
@Override
public TreeNode<Long, Long, TestNodeMeta, Long> withMeta(TestNodeMeta meta) {
return this.toBuilder().meta(meta).build();
return new TestTreeNode(key, parent, lastEffectiveOp, meta, children);
}
@Override
public TreeNode<Long, Long, TestNodeMeta, Long> withChildren(Map<String, Long> children) {
return this.toBuilder().children(children).build();
return new TestTreeNode(key, parent, lastEffectiveOp, meta, children);
}
}

View File

@@ -35,11 +35,6 @@
<groupId>net.openhft</groupId>
<artifactId>zero-allocation-hashing</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>

View File

@@ -1 +0,0 @@
lombok.accessors.prefix += _

View File

@@ -1,10 +1,11 @@
package com.usatiuk.dhfs.objects;
import jakarta.annotation.Nonnull;
import lombok.Builder;
import java.io.Serializable;
@Builder
public record JDataVersionedWrapper<T extends JData>(@Nonnull T data, long version) implements Serializable {
public JDataVersionedWrapper<T> withVersion(long version) {
return new JDataVersionedWrapper<>(data, version);
}
}

View File

@@ -12,7 +12,7 @@ public interface TransactionManager {
void rollback();
default <T> T run(Supplier<T> supplier) {
default <T> T runTries(Supplier<T> supplier, int tries) {
if (current() != null) {
return supplier.get();
}
@@ -23,14 +23,16 @@ public interface TransactionManager {
commit();
return ret;
} catch (TxCommitException txCommitException) {
return run(supplier);
if (tries == 0)
throw txCommitException;
return runTries(supplier, tries - 1);
} catch (Throwable e) {
rollback();
throw e;
}
}
default void run(VoidFn fn) {
default void runTries(VoidFn fn, int tries) {
if (current() != null) {
fn.apply();
return;
@@ -41,7 +43,9 @@ public interface TransactionManager {
fn.apply();
commit();
} catch (TxCommitException txCommitException) {
run(fn);
if (tries == 0)
throw txCommitException;
runTries(fn, tries - 1);
return;
} catch (Throwable e) {
rollback();
@@ -49,6 +53,14 @@ public interface TransactionManager {
}
}
default void run(VoidFn fn) {
runTries(fn, 10);
}
default <T> T run(Supplier<T> supplier) {
return runTries(supplier, 10);
}
default void executeTx(VoidFn fn) {
run(fn);
}

View File

@@ -10,7 +10,6 @@ import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import lombok.Getter;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -286,7 +285,6 @@ public class TxWritebackImpl implements TxWriteback {
private final LinkedHashMap<JObjectKey, BundleEntry> _entries = new LinkedHashMap<>();
private final ArrayList<VoidFn> _callbacks = new ArrayList<>();
private long _txId;
@Getter
private volatile boolean _ready = false;
private long _size = -1;
private boolean _wasCommitted = false;

View File

@@ -1,11 +1,9 @@
package com.usatiuk.dhfs.objects.transaction;
import com.usatiuk.dhfs.objects.JDataVersionedWrapper;
import com.usatiuk.dhfs.objects.JData;
import com.usatiuk.dhfs.objects.JDataVersionedWrapper;
import com.usatiuk.dhfs.objects.JObjectKey;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.AccessLevel;
import lombok.Getter;
import java.util.Collection;
import java.util.HashMap;
@@ -15,8 +13,12 @@ import java.util.Optional;
@ApplicationScoped
public class TransactionFactoryImpl implements TransactionFactory {
private class TransactionImpl implements TransactionPrivate {
@Getter(AccessLevel.PUBLIC)
private final long _id;
public long getId() {
return _id;
}
private final ReadTrackingObjectSource _source;
private final Map<JObjectKey, TxRecord.TxObjectRecord<?>> _writes = new HashMap<>();

View File

@@ -25,123 +25,91 @@ public class ObjectsTest {
@Test
void createObject() {
{
txm.begin();
var newParent = new Parent(JObjectKey.of("Parent"), "John");
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentCreate"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
var parent = curTx.get(Parent.class, JObjectKey.of("Parent")).orElse(null);
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentCreate")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
}
@Test
void createGetObject() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentCreateGet"), "John");
curTx.put(newParent);
var parent = curTx.get(Parent.class, JObjectKey.of("ParentCreateGet")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
{
txm.begin();
var parent = curTx.get(Parent.class, JObjectKey.of("ParentCreateGet")).orElse(null);
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentCreateGet")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
}
@Test
void createDeleteObject() {
{
txm.begin();
var newParent = new Parent(JObjectKey.of("Parent2"), "John");
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentCreateDeleteObject"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
var parent = curTx.get(Parent.class, JObjectKey.of("Parent2")).orElse(null);
txm.run(() -> {
var parent = curTx.get(Parent.class, JObjectKey.of("ParentCreateDeleteObject")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
{
txm.begin();
curTx.delete(new JObjectKey("Parent2"));
txm.commit();
}
txm.run(() -> {
curTx.delete(new JObjectKey("ParentCreateDeleteObject"));
});
{
txm.begin();
var parent = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentCreateDeleteObject")).orElse(null);
Assertions.assertNull(parent);
txm.commit();
}
});
}
@Test
void createCreateObject() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("Parent7"), "John");
curTx.put(newParent);
txm.commit();
}
{
txm.begin();
});
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("Parent7"), "John2");
curTx.put(newParent);
txm.commit();
}
{
txm.begin();
});
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("Parent7")).orElse(null);
Assertions.assertEquals("John2", parent.name());
txm.commit();
}
});
}
@Test
void editObject() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("Parent3"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("Parent3"), LockingStrategy.OPTIMISTIC).orElse(null);
Assertions.assertEquals("John", parent.name());
curTx.put(parent.toBuilder().name("John2").build());
txm.commit();
}
{
txm.begin();
curTx.put(parent.withName("John2"));
});
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("Parent3"), LockingStrategy.WRITE).orElse(null);
Assertions.assertEquals("John2", parent.name());
curTx.put(parent.toBuilder().name("John3").build());
txm.commit();
}
{
txm.begin();
curTx.put(parent.withName("John3"));
});
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("Parent3")).orElse(null);
Assertions.assertEquals("John3", parent.name());
txm.commit();
}
});
}
@Test
@@ -155,13 +123,17 @@ public class ObjectsTest {
Just.run(() -> {
try {
Log.warn("Thread 1");
txm.begin();
barrier.await();
var got = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
var newParent = new Parent(JObjectKey.of("Parent2"), "John");
curTx.put(newParent);
Log.warn("Thread 1 commit");
txm.commit();
txm.runTries(() -> {
try {
barrier.await();
} catch (Throwable e) {
throw new RuntimeException(e);
}
var got = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
var newParent = new Parent(JObjectKey.of("Parent2"), "John");
curTx.put(newParent);
Log.warn("Thread 1 commit");
}, 0);
thread1Failed.set(false);
return null;
} finally {
@@ -171,13 +143,17 @@ public class ObjectsTest {
Just.run(() -> {
try {
Log.warn("Thread 2");
txm.begin();
barrier.await();
var got = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
var newParent = new Parent(JObjectKey.of("Parent2"), "John2");
curTx.put(newParent);
Log.warn("Thread 2 commit");
txm.commit();
txm.runTries(() -> {
try {
barrier.await();
} catch (Throwable e) {
throw new RuntimeException(e);
}
var got = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
var newParent = new Parent(JObjectKey.of("Parent2"), "John2");
curTx.put(newParent);
Log.warn("Thread 2 commit");
}, 0);
thread2Failed.set(false);
return null;
} finally {
@@ -187,9 +163,9 @@ public class ObjectsTest {
latch.await();
txm.begin();
var got = curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
txm.commit();
var got = txm.run(() -> {
return curTx.get(Parent.class, new JObjectKey("Parent2")).orElse(null);
});
if (!thread1Failed.get()) {
Assertions.assertTrue(thread2Failed.get());
@@ -205,12 +181,10 @@ public class ObjectsTest {
@EnumSource(LockingStrategy.class)
void editConflict(LockingStrategy strategy) throws InterruptedException {
String key = "Parent4" + strategy.name();
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of(key), "John3");
curTx.put(newParent);
txm.commit();
}
});
AtomicBoolean thread1Failed = new AtomicBoolean(true);
AtomicBoolean thread2Failed = new AtomicBoolean(true);
@@ -221,12 +195,16 @@ public class ObjectsTest {
Just.run(() -> {
try {
Log.warn("Thread 1");
txm.begin();
barrier.await();
var parent = curTx.get(Parent.class, new JObjectKey(key), strategy).orElse(null);
curTx.put(parent.toBuilder().name("John").build());
Log.warn("Thread 1 commit");
txm.commit();
txm.runTries(() -> {
try {
barrier.await();
} catch (Throwable e) {
throw new RuntimeException(e);
}
var parent = curTx.get(Parent.class, new JObjectKey(key), strategy).orElse(null);
curTx.put(parent.withName("John"));
Log.warn("Thread 1 commit");
}, 0);
Log.warn("Thread 1 commit done");
thread1Failed.set(false);
return null;
@@ -237,12 +215,16 @@ public class ObjectsTest {
Just.run(() -> {
try {
Log.warn("Thread 2");
txm.begin();
barrier.await();
var parent = curTx.get(Parent.class, new JObjectKey(key), strategy).orElse(null);
curTx.put(parent.toBuilder().name("John2").build());
Log.warn("Thread 2 commit");
txm.commit();
txm.runTries(() -> {
try {
barrier.await();
} catch (Throwable e) {
throw new RuntimeException(e);
}
var parent = curTx.get(Parent.class, new JObjectKey(key), strategy).orElse(null);
curTx.put(parent.withName("John2"));
Log.warn("Thread 2 commit");
}, 0);
Log.warn("Thread 2 commit done");
thread2Failed.set(false);
return null;
@@ -253,9 +235,9 @@ public class ObjectsTest {
latchEnd.await();
txm.begin();
var got = curTx.get(Parent.class, new JObjectKey(key)).orElse(null);
txm.commit();
var got = txm.run(() -> {
return curTx.get(Parent.class, new JObjectKey(key)).orElse(null);
});
if (!thread1Failed.get()) {
Assertions.assertTrue(thread2Failed.get());

View File

@@ -28,49 +28,38 @@ public class PreCommitTxHookTest {
@Test
void createObject() {
{
txm.begin();
var newParent = new Parent(JObjectKey.of("ParentCreate"), "John");
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentCreate2"), "John");
curTx.put(newParent);
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
var parent = curTx.get(Parent.class, new JObjectKey("ParentCreate")).orElse(null);
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentCreate2")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
ArgumentCaptor<JData> dataCaptor = ArgumentCaptor.forClass(JData.class);
ArgumentCaptor<JObjectKey> keyCaptor = ArgumentCaptor.forClass(JObjectKey.class);
Mockito.verify(spyHook, Mockito.times(1)).onCreate(keyCaptor.capture(), dataCaptor.capture());
Assertions.assertEquals("John", ((Parent) dataCaptor.getValue()).name());
Assertions.assertEquals(new JObjectKey("ParentCreate"), keyCaptor.getValue());
Assertions.assertEquals(new JObjectKey("ParentCreate2"), keyCaptor.getValue());
}
@Test
void deleteObject() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentDel"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentDel")).orElse(null);
Assertions.assertEquals("John", parent.name());
txm.commit();
}
});
{
txm.begin();
txm.run(() -> {
curTx.delete(new JObjectKey("ParentDel"));
txm.commit();
}
});
ArgumentCaptor<JData> dataCaptor = ArgumentCaptor.forClass(JData.class);
ArgumentCaptor<JObjectKey> keyCaptor = ArgumentCaptor.forClass(JObjectKey.class);
@@ -81,19 +70,15 @@ public class PreCommitTxHookTest {
@Test
void editObject() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentEdit"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentEdit"), "John changed");
curTx.put(newParent);
txm.commit();
}
});
ArgumentCaptor<JData> dataCaptorOld = ArgumentCaptor.forClass(JData.class);
ArgumentCaptor<JData> dataCaptorNew = ArgumentCaptor.forClass(JData.class);
@@ -106,20 +91,16 @@ public class PreCommitTxHookTest {
@Test
void editObjectWithGet() {
{
txm.begin();
txm.run(() -> {
var newParent = new Parent(JObjectKey.of("ParentEdit2"), "John");
curTx.put(newParent);
txm.commit();
}
});
{
txm.begin();
txm.run(() -> {
var parent = curTx.get(Parent.class, new JObjectKey("ParentEdit2")).orElse(null);
Assertions.assertEquals("John", parent.name());
curTx.put(parent.toBuilder().name("John changed").build());
txm.commit();
}
curTx.put(parent.withName("John changed"));
});
ArgumentCaptor<JData> dataCaptorOld = ArgumentCaptor.forClass(JData.class);
ArgumentCaptor<JData> dataCaptorNew = ArgumentCaptor.forClass(JData.class);

View File

@@ -2,8 +2,9 @@ package com.usatiuk.dhfs.objects.data;
import com.usatiuk.dhfs.objects.JData;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
@Builder(toBuilder = true)
public record Kid(JObjectKey key, String name) implements JData {
public Kid withName(String name) {
return new Kid(key, name);
}
}

View File

@@ -2,8 +2,9 @@ package com.usatiuk.dhfs.objects.data;
import com.usatiuk.dhfs.objects.JData;
import com.usatiuk.dhfs.objects.JObjectKey;
import lombok.Builder;
@Builder(toBuilder = true)
public record Parent(JObjectKey key, String name) implements JData {
public Parent withName(String name) {
return new Parent(key, name);
}
}

View File

@@ -31,11 +31,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>

View File

@@ -1,7 +1,6 @@
package com.usatiuk.dhfs.utils;
import jakarta.annotation.Nullable;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Collection;

View File

@@ -0,0 +1,7 @@
package com.usatiuk.dhfs.utils;
@FunctionalInterface
public interface VoidFnThrows {
void apply() throws Throwable;
}