Repository: EventStore/EventStoreDB-Client-Java
Pull request #313 (2025-03-20 11:03:57)

Move ExpectedRevision to StreamState


Patch:
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStream.java b/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStream.java
index 5808fb6..11ef006 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStream.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStream.java
@@ -42,7 +42,7 @@ class AppendToStream {
 
     private CompletableFuture<WriteResult> append(ManagedChannel channel, List<EventData> events) {
         CompletableFuture<WriteResult> result = new CompletableFuture<>();
-        StreamsOuterClass.AppendReq.Options.Builder options = this.options.getExpectedRevision().applyOnWire(StreamsOuterClass.AppendReq.Options.newBuilder()
+        StreamsOuterClass.AppendReq.Options.Builder options = this.options.getStreamState().applyOnWire(StreamsOuterClass.AppendReq.Options.newBuilder()
                 .setStreamIdentifier(Shared.StreamIdentifier.newBuilder()
                         .setStreamName(ByteString.copyFromUtf8(streamName))
                         .build()));
@@ -58,33 +58,33 @@ class AppendToStream {
                     logPosition = new Position(p.getCommitPosition(), p.getPreparePosition());
                 }
 
-                ExpectedRevision nextExpectedRevision = success.hasNoStream() ? ExpectedRevision.noStream()
-                        : ExpectedRevision.expectedRevision(success.getCurrentRevision());
+                StreamState nextExpectedRevision = success.hasNoStream() ? StreamState.noStream()
+                        : StreamState.streamRevision(success.getCurrentRevision());
 
                 return new WriteResult(nextExpectedRevision, logPosition);
             }
             if (resp.hasWrongExpectedVersion()) {
                 StreamsOuterClass.AppendResp.WrongExpectedVersion wev = resp.getWrongExpectedVersion();
 
-                ExpectedRevision expectedRevision;
+                StreamState expectedRevision;
                 if (wev.getExpectedRevisionOptionCase() == StreamsOuterClass.AppendResp.WrongExpectedVersion.ExpectedRevisionOptionCase.EXPECTED_ANY) {
-                    expectedRevision = ExpectedRevision.any();
+                    expectedRevision = StreamState.any();
                 } else if (wev.getExpectedRevisionOptionCase() == StreamsOuterClass.AppendResp.WrongExpectedVersion.ExpectedRevisionOptionCase.EXPECTED_STREAM_EXISTS) {
-                    expectedRevision = ExpectedRevision.streamExists();
+                    expectedRevision = StreamState.streamExists();
                 } else {
-                    expectedRevision = ExpectedRevision.expectedRevision(wev.getExpectedRevision());
+                    expectedRevision = StreamState.streamRevision(wev.getExpectedRevision());
                 }
 
-                ExpectedRevision currentRevision;
+                StreamState streamState;
                 if (wev.getCurrentRevisionOptionCase() == StreamsOuterClass.AppendResp.WrongExpectedVersion.CurrentRevisionOptionCase.CURRENT_NO_STREAM) {
-                    currentRevision = ExpectedRevision.noStream();
+                    streamState = StreamState.noStream();
                 } else {
-                    currentRevision = ExpectedRevision.expectedRevision(wev.getCurrentRevision());
+                    streamState = StreamState.streamRevision(wev.getCurrentRevision());
                 }
 
                 String streamName = options.getStreamIdentifier().getStreamName().toStringUtf8();
 
-                throw new WrongExpectedVersionException(streamName, expectedRevision, currentRevision);
+                throw new WrongExpectedVersionException(streamName, expectedRevision, streamState);
             }
 
             throw new IllegalStateException("AppendResponse has neither Success or WrongExpectedVersion variants");
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStreamOptions.java b/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStreamOptions.java
index ec98618..3dd3f2b 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStreamOptions.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/AppendToStreamOptions.java
@@ -3,7 +3,7 @@ package io.kurrent.dbclient;
 /**
  * Options of the append stream request.
  */
-public class AppendToStreamOptions extends OptionsWithExpectedRevisionBase<AppendToStreamOptions> {
+public class AppendToStreamOptions extends OptionsWithStreamStateBase<AppendToStreamOptions> {
     private AppendToStreamOptions() {
     }
 
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/GrpcUtils.java b/db-client-java/src/main/java/io/kurrent/dbclient/GrpcUtils.java
index d381d14..9dce224 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/GrpcUtils.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/GrpcUtils.java
@@ -61,8 +61,8 @@ final class GrpcUtils {
                             }
 
                             try {
-                                ExpectedRevision expected = ExpectedRevision.fromRawLong(Long.parseLong(expectedStr));
-                                ExpectedRevision actual = ExpectedRevision.fromRawLong(Long.parseLong(actualStr));
+                                StreamState expected = StreamState.fromRawLong(Long.parseLong(expectedStr));
+                                StreamState actual = StreamState.fromRawLong(Long.parseLong(actualStr));
 
                                 dest.completeExceptionally(new WrongExpectedVersionException(streamName, expected, actual));
                                 return;
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithExpectedRevisionBase.java b/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithExpectedRevisionBase.java
deleted file mode 100644
index b812e11..0000000
--- a/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithExpectedRevisionBase.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package io.kurrent.dbclient;
-
-class OptionsWithExpectedRevisionBase<T> extends OptionsBase<T> {
-    private ExpectedRevision expectedRevision;
-
-    protected OptionsWithExpectedRevisionBase() {
-        this.expectedRevision = ExpectedRevision.any();
-    }
-
-    ExpectedRevision getExpectedRevision() {
-        return this.expectedRevision;
-    }
-
-    /**
-     * Asks the server to check that the stream receiving is at the given expected version.
-
-     * @param revision - expected revision.
-     * @return updated options.
-     */
-    @SuppressWarnings("unchecked")
-    public T expectedRevision(ExpectedRevision revision) {
-        this.expectedRevision = revision;
-        return (T) this;
-    }
-
-
-    /**
-     * Asks the server to check that the stream receiving is at the given expected version.
-
-     * @param revision - expected revision.
-     * @return updated options.
-     */
-    public T expectedRevision(long revision) {
-        return expectedRevision(ExpectedRevision.expectedRevision(revision));
-    }
-}
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithStreamStateBase.java b/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithStreamStateBase.java
new file mode 100644
index 0000000..48eef35
--- /dev/null
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/OptionsWithStreamStateBase.java
@@ -0,0 +1,36 @@
+package io.kurrent.dbclient;
+
+class OptionsWithStreamStateBase<T> extends OptionsBase<T> {
+    private StreamState streamState;
+
+    protected OptionsWithStreamStateBase() {
+        this.streamState = StreamState.any();
+    }
+
+    StreamState getStreamState() {
+        return this.streamState;
+    }
+
+    /**
+     * Asks the server to check that the stream receiving is at the expected state.
+
+     * @param state - expected revision.
+     * @return updated options.
+     */
+    @SuppressWarnings("unchecked")
+    public T streamState(StreamState state) {
+        this.streamState = state;
+        return (T) this;
+    }
+
+
+    /**
+     * Asks the server to check that the stream receiving is at the given expected revision.
+
+     * @param revision - expected revision.
+     * @return updated options.
+     */
+    public T streamRevision(long revision) {
+        return streamState(StreamState.streamRevision(revision));
+    }
+}
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/ExpectedRevision.java b/db-client-java/src/main/java/io/kurrent/dbclient/StreamState.java
similarity index 76%
rename from db-client-java/src/main/java/io/kurrent/dbclient/ExpectedRevision.java
rename to db-client-java/src/main/java/io/kurrent/dbclient/StreamState.java
index d03cd49..71831b8 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/ExpectedRevision.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/StreamState.java
@@ -14,66 +14,66 @@ import java.util.Objects;
  * guarantee it. Any other <i>ExpectedRevision</i> instances are meant for optimistic concurrency checks.
  * </p>
  */
-public abstract class ExpectedRevision {
+public abstract class StreamState {
     /**
      * This writes should not conflict with anything and should always succeed.
      */
-    public static ExpectedRevision any() {
-        return new AnyExpectedRevision();
+    public static StreamState any() {
+        return new AnyStreamState();
     }
 
     /**
      * The stream being written to should not yet exist. If it does exist, treats that as a concurrency problem.
      */
-    public static ExpectedRevision noStream() {
-        return new NoStreamExpectedRevision();
+    public static StreamState noStream() {
+        return new NoStreamState();
     }
 
     /**
      * The stream should exist. If it or a metadata stream does not exist, treats that as a concurrency problem.
      */
-    public static ExpectedRevision streamExists() {
-        return new StreamExistsExpectedRevision();
+    public static StreamState streamExists() {
+        return new StreamExistsState();
     }
 
     /**
      * States that the last event written to the stream should have an event revision matching your expected value.
      */
-    public static ExpectedRevision expectedRevision(long revision) {
-        return new SpecificExpectedRevision(revision);
+    public static StreamState streamRevision(long revision) {
+        return new StreamRevisionStreamState(revision);
     }
 
-    public static ExpectedRevision fromRawLong(long revision) {
+    public static StreamState fromRawLong(long revision) {
         if (revision == -1)
-            return ExpectedRevision.noStream();
+            return StreamState.noStream();
         if (revision == -2)
-            return ExpectedRevision.any();
+            return StreamState.any();
         if (revision == -4)
-            return ExpectedRevision.streamExists();
+            return StreamState.streamExists();
 
         if (revision < 0)
-            throw new RuntimeException(String.format("Invalid expected revision long representation '%s'", revision));
+            throw new RuntimeException(String.format("Invalid stream revision long representation '%s'", revision));
 
-        return ExpectedRevision.expectedRevision(revision);
+        return StreamState.streamRevision(revision);
     }
 
-    ExpectedRevision() {}
+    StreamState() {}
 
     abstract StreamsOuterClass.AppendReq.Options.Builder applyOnWire(StreamsOuterClass.AppendReq.Options.Builder options);
     abstract StreamsOuterClass.DeleteReq.Options.Builder applyOnWire(StreamsOuterClass.DeleteReq.Options.Builder options);
     abstract StreamsOuterClass.TombstoneReq.Options.Builder applyOnWire(StreamsOuterClass.TombstoneReq.Options.Builder options);
 
     public long toRawLong() {
-        if (this instanceof  NoStreamExpectedRevision)
+        if (this instanceof NoStreamState)
             return -1;
 
-        if (this instanceof AnyExpectedRevision)
+        if (this instanceof AnyStreamState)
             return -2;
 
-        if (this instanceof StreamExistsExpectedRevision)
+        if (this instanceof StreamExistsState)
             return -4;
 
-        SpecificExpectedRevision revision = (SpecificExpectedRevision) this;
+        StreamRevisionStreamState revision = (StreamRevisionStreamState) this;
 
         return revision.version;
     }
@@ -89,7 +89,7 @@ public abstract class ExpectedRevision {
         return Objects.hash(getClass());
     }
 
-    public static class NoStreamExpectedRevision extends ExpectedRevision {
+    public static class NoStreamState extends StreamState {
         @Override
         public StreamsOuterClass.AppendReq.Options.Builder applyOnWire(StreamsOuterClass.AppendReq.Options.Builder options) {
             return options.setNoStream(Shared.Empty.getDefaultInstance());
@@ -107,11 +107,11 @@ public abstract class ExpectedRevision {
 
         @Override
         public String toString() {
-            return "ExpectedNoStream";
+            return "NoStreamState";
         }
     }
 
-    public static class AnyExpectedRevision extends ExpectedRevision {
+    public static class AnyStreamState extends StreamState {
         @Override
         public StreamsOuterClass.AppendReq.Options.Builder applyOnWire(StreamsOuterClass.AppendReq.Options.Builder options) {
             return options.setAny(Shared.Empty.getDefaultInstance());
@@ -129,11 +129,11 @@ public abstract class ExpectedRevision {
 
         @Override
         public String toString() {
-            return "ExpectedAny";
+            return "AnyStreamState";
         }
     }
 
-    public static class StreamExistsExpectedRevision extends ExpectedRevision {
+    public static class StreamExistsState extends StreamState {
         @Override
         public StreamsOuterClass.AppendReq.Options.Builder applyOnWire(StreamsOuterClass.AppendReq.Options.Builder options) {
             return options.setStreamExists(Shared.Empty.getDefaultInstance());
@@ -151,14 +151,14 @@ public abstract class ExpectedRevision {
 
         @Override
         public String toString() {
-            return "ExpectedStreamExists";
+            return "StreamExistsState";
         }
     }
 
-    public static class SpecificExpectedRevision extends ExpectedRevision {
+    public static class StreamRevisionStreamState extends StreamState {
         final long version;
 
-        SpecificExpectedRevision(long version) {
+        StreamRevisionStreamState(long version) {
             this.version = version;
         }
 
@@ -166,7 +166,7 @@ public abstract class ExpectedRevision {
         public boolean equals(Object o) {
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
-            SpecificExpectedRevision that = (SpecificExpectedRevision) o;
+            StreamRevisionStreamState that = (StreamRevisionStreamState) o;
             return version == that.version;
         }
 
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/WriteResult.java b/db-client-java/src/main/java/io/kurrent/dbclient/WriteResult.java
index aef33ab..b4feada 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/WriteResult.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/WriteResult.java
@@ -6,10 +6,10 @@ import java.util.Objects;
  * Returned after writing to a stream.
  */
 public class WriteResult {
-    private final ExpectedRevision nextExpectedRevision;
+    private final StreamState nextExpectedRevision;
     private final Position logPosition;
 
-    WriteResult(ExpectedRevision nextExpectedRevision, Position logPosition) {
+    WriteResult(StreamState nextExpectedRevision, Position logPosition) {
         this.nextExpectedRevision = nextExpectedRevision;
         this.logPosition = logPosition;
     }
@@ -17,7 +17,7 @@ public class WriteResult {
     /**
      * Next expected version of the stream.
      */
-    public ExpectedRevision getNextExpectedRevision() {
+    public StreamState getNextExpectedRevision() {
         return nextExpectedRevision;
     }
 
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/WrongExpectedVersionException.java b/db-client-java/src/main/java/io/kurrent/dbclient/WrongExpectedVersionException.java
index 07878fa..06dab32 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/WrongExpectedVersionException.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/WrongExpectedVersionException.java
@@ -7,17 +7,17 @@ import javax.validation.constraints.NotNull;
  */
 public class WrongExpectedVersionException extends RuntimeException {
     private final String streamName;
-    private final ExpectedRevision nextExpectedRevision;
-    private final ExpectedRevision actualRevision;
+    private final StreamState expectedState;
+    private final StreamState actualState;
 
     WrongExpectedVersionException(
             @NotNull String streamName,
-            @NotNull ExpectedRevision nextExpected,
-            @NotNull ExpectedRevision actualRevision) {
-        super(String.format("Expected %s but got %s instead", nextExpected, actualRevision));
+            @NotNull StreamState expectedState,
+            @NotNull StreamState actualState) {
+        super(String.format("Expected %s but got %s instead", expectedState, actualState));
         this.streamName = streamName;
-        this.nextExpectedRevision = nextExpected;
-        this.actualRevision = actualRevision;
+        this.expectedState = expectedState;
+        this.actualState = actualState;
     }
 
     /**
@@ -28,16 +28,16 @@ public class WrongExpectedVersionException extends RuntimeException {
     }
 
     /**
-     * Returns the expected revision by the request.
+     * Returns the expected stream state by the request.
      */
-    public ExpectedRevision getNextExpectedRevision() {
-        return nextExpectedRevision;
+    public StreamState getExpectedState() {
+        return expectedState;
     }
 
     /**
-     * Returns the actual revision of the stream when the check was performed.
+     * Returns the actual stream state when the check was performed.
      */
-    public ExpectedRevision getActualVersion() {
-        return actualRevision;
+    public StreamState getActualState() {
+        return actualState;
     }
 }


Test patch:
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStream.java b/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStream.java
index 4741d30..05777c3 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStream.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStream.java
@@ -4,7 +4,6 @@ import io.kurrent.dbclient.proto.shared.Shared;
 import io.kurrent.dbclient.proto.streams.StreamsGrpc;
 import io.kurrent.dbclient.proto.streams.StreamsOuterClass;
 import com.google.protobuf.ByteString;
-import io.grpc.Metadata;
 
 import java.util.concurrent.CompletableFuture;
 
@@ -28,7 +27,7 @@ class DeleteStream {
 
             if (this.softDelete) {
                 StreamsOuterClass.DeleteReq req = StreamsOuterClass.DeleteReq.newBuilder()
-                        .setOptions(this.options.getExpectedRevision().applyOnWire(StreamsOuterClass.DeleteReq.Options.newBuilder()
+                        .setOptions(this.options.getStreamState().applyOnWire(StreamsOuterClass.DeleteReq.Options.newBuilder()
                                 .setStreamIdentifier(Shared.StreamIdentifier.newBuilder()
                                         .setStreamName(ByteString.copyFromUtf8(streamName))
                                         .build())))
@@ -45,7 +44,7 @@ class DeleteStream {
             }
 
             StreamsOuterClass.TombstoneReq req = StreamsOuterClass.TombstoneReq.newBuilder()
-                    .setOptions(this.options.getExpectedRevision().applyOnWire(StreamsOuterClass.TombstoneReq.Options.newBuilder()
+                    .setOptions(this.options.getStreamState().applyOnWire(StreamsOuterClass.TombstoneReq.Options.newBuilder()
                             .setStreamIdentifier(Shared.StreamIdentifier.newBuilder()
                                     .setStreamName(ByteString.copyFromUtf8(streamName))
                                     .build())))
diff --git a/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStreamOptions.java b/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStreamOptions.java
index a02b0e3..6ed6a8d 100644
--- a/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStreamOptions.java
+++ b/db-client-java/src/main/java/io/kurrent/dbclient/DeleteStreamOptions.java
@@ -3,7 +3,7 @@ package io.kurrent.dbclient;
 /**
  * Options of the delete or tombstone stream request.
  */
-public class DeleteStreamOptions extends OptionsWithExpectedRevisionBase<DeleteStreamOptions> {
+public class DeleteStreamOptions extends OptionsWithStreamStateBase<DeleteStreamOptions> {
     DeleteStreamOptions() {}
 
     /**
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/misc/ExpectedRevisionTests.java b/db-client-java/src/test/java/io/kurrent/dbclient/misc/ExpectedRevisionTests.java
index 369663c..cf974d5 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/misc/ExpectedRevisionTests.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/misc/ExpectedRevisionTests.java
@@ -1,7 +1,7 @@
 package io.kurrent.dbclient.misc;
 
 
-import io.kurrent.dbclient.ExpectedRevision;
+import io.kurrent.dbclient.StreamState;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -9,52 +9,52 @@ public class ExpectedRevisionTests {
 
     @Test
     public void testExpectedRevisionEquality() {
-        Assertions.assertEquals(ExpectedRevision.any(), new ExpectedRevision.AnyExpectedRevision());
-        Assertions.assertEquals(ExpectedRevision.noStream(), new ExpectedRevision.NoStreamExpectedRevision());
-        Assertions.assertEquals(ExpectedRevision.streamExists(), new ExpectedRevision.StreamExistsExpectedRevision());
-        Assertions.assertEquals(ExpectedRevision.expectedRevision(1L), ExpectedRevision.expectedRevision(1L));
+        Assertions.assertEquals(StreamState.any(), new StreamState.AnyStreamState());
+        Assertions.assertEquals(StreamState.noStream(), new StreamState.NoStreamState());
+        Assertions.assertEquals(StreamState.streamExists(), new StreamState.StreamExistsState());
+        Assertions.assertEquals(StreamState.streamRevision(1L), StreamState.streamRevision(1L));
     }
 
     @Test
     public void testExpectedRevisionNonEquality() {
-        Assertions.assertNotEquals(ExpectedRevision.any(), ExpectedRevision.noStream());
-        Assertions.assertNotEquals(ExpectedRevision.any(), ExpectedRevision.streamExists());
-        Assertions.assertNotEquals(ExpectedRevision.any(), ExpectedRevision.expectedRevision(0L));
-        Assertions.assertNotEquals(ExpectedRevision.noStream(), ExpectedRevision.streamExists());
-        Assertions.assertNotEquals(ExpectedRevision.noStream(), ExpectedRevision.expectedRevision(0L));
-        Assertions.assertNotEquals(ExpectedRevision.streamExists(), ExpectedRevision.expectedRevision(0L));
+        Assertions.assertNotEquals(StreamState.any(), StreamState.noStream());
+        Assertions.assertNotEquals(StreamState.any(), StreamState.streamExists());
+        Assertions.assertNotEquals(StreamState.any(), StreamState.streamRevision(0L));
+        Assertions.assertNotEquals(StreamState.noStream(), StreamState.streamExists());
+        Assertions.assertNotEquals(StreamState.noStream(), StreamState.streamRevision(0L));
+        Assertions.assertNotEquals(StreamState.streamExists(), StreamState.streamRevision(0L));
     }
 
     @Test
     public void testExpectedRevisionHashCode() {
-        Assertions.assertEquals(ExpectedRevision.any().hashCode(), new ExpectedRevision.AnyExpectedRevision().hashCode());
-        Assertions.assertEquals(ExpectedRevision.noStream().hashCode(), new ExpectedRevision.NoStreamExpectedRevision().hashCode());
-        Assertions.assertEquals(ExpectedRevision.streamExists().hashCode(), new ExpectedRevision.StreamExistsExpectedRevision().hashCode());
-        Assertions.assertEquals(ExpectedRevision.expectedRevision(1L).hashCode(), ExpectedRevision.expectedRevision(1L).hashCode());
+        Assertions.assertEquals(StreamState.any().hashCode(), new StreamState.AnyStreamState().hashCode());
+        Assertions.assertEquals(StreamState.noStream().hashCode(), new StreamState.NoStreamState().hashCode());
+        Assertions.assertEquals(StreamState.streamExists().hashCode(), new StreamState.StreamExistsState().hashCode());
+        Assertions.assertEquals(StreamState.streamRevision(1L).hashCode(), StreamState.streamRevision(1L).hashCode());
     }
 
     @Test
     public void testHumanRepresentation() {
-        Assertions.assertEquals("ExpectedAny", ExpectedRevision.any().toString());
-        Assertions.assertEquals("ExpectedStreamExists", ExpectedRevision.streamExists().toString());
-        Assertions.assertEquals("ExpectedNoStream", ExpectedRevision.noStream().toString());
-        Assertions.assertEquals("42", ExpectedRevision.expectedRevision(42).toString());
+        Assertions.assertEquals("AnyStreamState", StreamState.any().toString());
+        Assertions.assertEquals("StreamExistsState", StreamState.streamExists().toString());
+        Assertions.assertEquals("NoStreamState", StreamState.noStream().toString());
+        Assertions.assertEquals("42", StreamState.streamRevision(42).toString());
     }
 
     @Test
     public void testRawLong() {
-        Assertions.assertEquals(-2, ExpectedRevision.any().toRawLong());
-        Assertions.assertEquals(-1, ExpectedRevision.noStream().toRawLong());
-        Assertions.assertEquals(-4, ExpectedRevision.streamExists().toRawLong());
-        Assertions.assertEquals(42, ExpectedRevision.expectedRevision(42).toRawLong());
+        Assertions.assertEquals(-2, StreamState.any().toRawLong());
+        Assertions.assertEquals(-1, StreamState.noStream().toRawLong());
+        Assertions.assertEquals(-4, StreamState.streamExists().toRawLong());
+        Assertions.assertEquals(42, StreamState.streamRevision(42).toRawLong());
     }
 
     @Test
     public void testRawLongConversion() {
-        Assertions.assertEquals(ExpectedRevision.fromRawLong(-2), ExpectedRevision.any());
-        Assertions.assertEquals(ExpectedRevision.fromRawLong(-1), ExpectedRevision.noStream());
-        Assertions.assertEquals(ExpectedRevision.fromRawLong(-4), ExpectedRevision.streamExists());
-        Assertions.assertEquals(ExpectedRevision.fromRawLong(42), ExpectedRevision.expectedRevision(42));
-        Assertions.assertThrowsExactly(RuntimeException.class, () -> ExpectedRevision.fromRawLong(-5));
+        Assertions.assertEquals(StreamState.fromRawLong(-2), StreamState.any());
+        Assertions.assertEquals(StreamState.fromRawLong(-1), StreamState.noStream());
+        Assertions.assertEquals(StreamState.fromRawLong(-4), StreamState.streamExists());
+        Assertions.assertEquals(StreamState.fromRawLong(42), StreamState.streamRevision(42));
+        Assertions.assertThrowsExactly(RuntimeException.class, () -> StreamState.fromRawLong(-5));
     }
 }
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/samples/appending_events/AppendingEvents.java b/db-client-java/src/test/java/io/kurrent/dbclient/samples/appending_events/AppendingEvents.java
index a6a0c7b..0115492 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/samples/appending_events/AppendingEvents.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/samples/appending_events/AppendingEvents.java
@@ -20,7 +20,7 @@ public class AppendingEvents {
                 .build();
 
         AppendToStreamOptions options = AppendToStreamOptions.get()
-                .expectedRevision(ExpectedRevision.noStream());
+                .streamState(StreamState.noStream());
 
         client.appendToStream("some-stream", options, eventData)
                 .get();
@@ -40,7 +40,7 @@ public class AppendingEvents {
                 .build();
 
         AppendToStreamOptions options = AppendToStreamOptions.get()
-                .expectedRevision(ExpectedRevision.any());
+                .streamState(StreamState.any());
 
         client.appendToStream("same-event-stream", options, eventData)
                 .get();
@@ -74,7 +74,7 @@ public class AppendingEvents {
                 .build();
 
         AppendToStreamOptions options = AppendToStreamOptions.get()
-                .expectedRevision(ExpectedRevision.noStream());
+                .streamState(StreamState.noStream());
 
         client.appendToStream("no-stream-stream", options, eventDataOne)
                 .get();
@@ -117,7 +117,7 @@ public class AppendingEvents {
 
 
         AppendToStreamOptions options = AppendToStreamOptions.get()
-                .expectedRevision(result.getLastStreamPosition());
+                .streamRevision(result.getLastStreamPosition());
 
         client.appendToStream("concurrency-stream", options, clientOneData)
                 .get();
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/samples/opentelemetry/Instrumentation.java b/db-client-java/src/test/java/io/kurrent/dbclient/samples/opentelemetry/Instrumentation.java
index ab47f33..c94d89f 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/samples/opentelemetry/Instrumentation.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/samples/opentelemetry/Instrumentation.java
@@ -55,7 +55,7 @@ public class Instrumentation {
         // endregion setup-client-for-tracing
 
         AppendToStreamOptions options = AppendToStreamOptions.get()
-                .expectedRevision(ExpectedRevision.any());
+                .streamState(StreamState.any());
 
         WriteResult appendResult = client.appendToStream("some-stream", options, eventData)
                 .get();
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/streams/AppendTests.java b/db-client-java/src/test/java/io/kurrent/dbclient/streams/AppendTests.java
index a569d13..72701fd 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/streams/AppendTests.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/streams/AppendTests.java
@@ -24,12 +24,12 @@ public interface AppendTests extends ConnectionAware {
                 .build();
 
         AppendToStreamOptions appendOptions = AppendToStreamOptions.get()
-                .expectedRevision(ExpectedRevision.noStream());
+                .streamState(StreamState.noStream());
 
         WriteResult appendResult = client.appendToStream(streamName, appendOptions, event)
                 .get();
 
-        Assertions.assertEquals(ExpectedRevision.expectedRevision(0), appendResult.getNextExpectedRevision());
+        Assertions.assertEquals(StreamState.streamRevision(0), appendResult.getNextExpectedRevision());
 
         ReadStreamOptions readStreamOptions = ReadStreamOptions.get()
                 .fromEnd()
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/streams/DeleteTests.java b/db-client-java/src/test/java/io/kurrent/dbclient/streams/DeleteTests.java
index 9d94550..60cae72 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/streams/DeleteTests.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/streams/DeleteTests.java
@@ -39,7 +39,7 @@ public interface DeleteTests extends ConnectionAware {
 
         String streamName = generateName();
         DeleteStreamOptions options = DeleteStreamOptions.get()
-            .expectedRevision(ExpectedRevision.streamExists());
+            .streamState(StreamState.streamExists());
 
         Assertions.assertThrows(WrongExpectedVersionException.class, () -> {
             try {
diff --git a/db-client-java/src/test/java/io/kurrent/dbclient/telemetry/StreamsTracingInstrumentationTests.java b/db-client-java/src/test/java/io/kurrent/dbclient/telemetry/StreamsTracingInstrumentationTests.java
index b90587a..892814b 100644
--- a/db-client-java/src/test/java/io/kurrent/dbclient/telemetry/StreamsTracingInstrumentationTests.java
+++ b/db-client-java/src/test/java/io/kurrent/dbclient/telemetry/StreamsTracingInstrumentationTests.java
@@ -23,7 +23,7 @@ public interface StreamsTracingInstrumentationTests extends TelemetryAware {
 
         client.appendToStream(
                         streamName,
-                        AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
+                        AppendToStreamOptions.get().streamState(StreamState.noStream()),
                         EventData.builderAsJson("TestEvent", mapper.writeValueAsBytes(new Foo()))
                                 .eventId(UUID.randomUUID())
                                 .build())
@@ -42,7 +42,7 @@ public interface StreamsTracingInstrumentationTests extends TelemetryAware {
 
         client.appendToStream(
                         streamName,
-                        AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
+                        AppendToStreamOptions.get().streamState(StreamState.noStream()),
                         EventData.builderAsJson("TestEvent", mapper.writeValueAsBytes(new Foo()))
                                 .metadataAsBytes(mapper.writeValueAsBytes(new Foo()))
                                 .eventId(UUID.randomUUID())
@@ -82,7 +82,7 @@ public interface StreamsTracingInstrumentationTests extends TelemetryAware {
 
         client.appendToStream(
                         streamName,
-                        AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream()),
+                        AppendToStreamOptions.get().streamState(StreamState.noStream()),
                         eventWithValidMetadata,
                         eventWithInvalidMetadata)
                 .get();
@@ -132,7 +132,7 @@ public interface StreamsTracingInstrumentationTests extends TelemetryAware {
             client.appendToStream(
                             streamName,
                             // Force WrongExpectedVersionException to be thrown.
-                            AppendToStreamOptions.get().expectedRevision(ExpectedRevision.streamExists()),
+                            AppendToStreamOptions.get().streamState(StreamState.streamExists()),
                             EventData.builderAsJson("TestEvent", mapper.writeValueAsBytes(new Foo()))
                                     .eventId(UUID.randomUUID())
                                     .build())
@@ -263,7 +263,7 @@ public interface StreamsTracingInstrumentationTests extends TelemetryAware {
         WriteResult appendResult = client.appendToStream(streamName, events).get();
         Assertions.assertNotNull(appendResult);
 
-        DeleteResult deleteResult = client.deleteStream(streamName, DeleteStreamOptions.get().expectedRevision(ExpectedRevision.streamExists())).get();
+        DeleteResult deleteResult = client.deleteStream(streamName, DeleteStreamOptions.get().streamState(StreamState.streamExists())).get();
         Assertions.assertNotNull(deleteResult);
 
         CountDownLatch subscribeSpansLatch = new CountDownLatch(events.length);