Return empty metadata for key not found + add IT test. (#528)

This commit is contained in:
Artur Souza 2021-05-14 11:37:09 -07:00 committed by GitHub
parent dfd0d5c7af
commit 33f793c186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import java.util.List;
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;
@ -249,6 +250,52 @@ public abstract class AbstractStateClientIT extends BaseIT {
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());
// 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() {

View File

@ -521,7 +521,7 @@ public class DaprClientHttp extends AbstractDaprClient {
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);
}
/**