Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -249,6 +250,52 @@ public void saveUpdateAndGetStateWithEtag() {
assertEquals("data in property B2", myDataResponse.getValue().getPropertyB());
}

@Test
public void saveUpdateAndGetNullStateWithEtag() {
// The key use to store the state and be updated using etags
final String stateKey = UUID.randomUUID().toString();
DaprClient daprClient = buildDaprClient();
MyData data = new MyData();
data.setPropertyA("data in property A");
data.setPropertyB("data in property B");

// Get state to validate case for key not found.
State<MyData> stateNotFound = daprClient.getState(STATE_STORE_NAME, stateKey, MyData.class).block();
assertEquals(stateKey, stateNotFound.getKey());
assertNull(stateNotFound.getValue());
assertNull(stateNotFound.getEtag());
assertNull(stateNotFound.getOptions());
assertNull(stateNotFound.getError());
assertEquals(0, stateNotFound.getMetadata().size());

// Set non null value
daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null).block();

// Get state to validate case for key with value.
State<MyData> stateFound = daprClient.getState(STATE_STORE_NAME, stateKey, MyData.class).block();
assertEquals(stateKey, stateFound.getKey());
assertNotNull(stateFound.getValue());
assertEquals("data in property A", stateFound.getValue().getPropertyA());
assertEquals("data in property B", stateFound.getValue().getPropertyB());
assertNotNull(stateFound.getEtag());
assertFalse(stateFound.getEtag().isEmpty());
assertNull(stateFound.getOptions());
assertNull(stateFound.getError());
assertEquals(0, stateFound.getMetadata().size());
Comment thread
artursouza marked this conversation as resolved.

// Set to null value
daprClient.saveState(STATE_STORE_NAME, stateKey, null, null, null).block();

// Get state to validate case for key not found.
State<MyData> stateNullValue = daprClient.getState(STATE_STORE_NAME, stateKey, MyData.class).block();
assertEquals(stateKey, stateNullValue.getKey());
assertNull(stateNullValue.getValue());
assertNotNull(stateNullValue.getEtag());
assertFalse(stateNullValue.getEtag().isEmpty());
assertNull(stateNullValue.getOptions());
assertNull(stateNullValue.getError());
assertEquals(0, stateNullValue.getMetadata().size());
}

@Test(expected = RuntimeException.class)
public void saveUpdateAndGetStateWithWrongEtag() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/dapr/client/DaprClientHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private <T> State<T> buildState(
if (response.getHeaders() != null && response.getHeaders().containsKey("Etag")) {
etag = response.getHeaders().get("Etag");
}
return new State<>(requestedKey, value, etag, stateOptions);
return new State<>(requestedKey, value, etag, Collections.emptyMap(), stateOptions);
}

/**
Expand Down