Add support for dapr 0.4 (multi-state store) (#199)

* Updating proto file from dapr.

* Adding support for multi-state store.

* Allow PubSubIT to get accept events out of order.

Co-authored-by: Shalabh Mohan Shrivastava <shalabhms@gmail.com>
This commit is contained in:
Artur Souza 2020-02-04 13:31:57 -08:00 committed by GitHub
parent af44053198
commit bbbd4be648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 493 additions and 345 deletions

View File

@ -5,7 +5,6 @@ on:
branches: branches:
- master - master
- release-* - release-*
- java_sdk_wip
tags: tags:
- v* - v*
@ -13,31 +12,70 @@ on:
branches: branches:
- master - master
- release-* - release-*
- java_sdk_wip
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GOVER: 1.13.7
GOOS: linux
GOARCH: amd64
GOPROXY: https://proxy.golang.org
JDK_VER: 13.0.x JDK_VER: 13.0.x
DAPR_RUNTIME_VER: 0.3.0 DAPR_RUNTIME_VER: 0.3.0
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/f84566fb2bf5a599252ab9d6bd82fc78faf94dba/install/install.sh
DAPR_CLI_REF: f84566fb2bf5a599252ab9d6bd82fc78faf94dba
DAPR_REF: e540a7166aeaf115773ccc4c7a1056ae7eed073b
OSSRH_USER_TOKEN: ${{ secrets.OSSRH_USER_TOKEN }} OSSRH_USER_TOKEN: ${{ secrets.OSSRH_USER_TOKEN }}
OSSRH_PWD_TOKEN: ${{ secrets.OSSRH_PWD_TOKEN }} OSSRH_PWD_TOKEN: ${{ secrets.OSSRH_PWD_TOKEN }}
GPG_KEY: ${{ secrets.GPG_KEY }} GPG_KEY: ${{ secrets.GPG_KEY }}
GPG_PWD: ${{ secrets.GPG_PWD }} GPG_PWD: ${{ secrets.GPG_PWD }}
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- name: Set up OpenJDK ${{ env.JDK_VER }} - name: Set up OpenJDK ${{ env.JDK_VER }}
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: ${{ env.JDK_VER }} java-version: ${{ env.JDK_VER }}
- name: Set up Dapr CLI - name: Set up Dapr CLI
run: wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash run: wget -q ${{ env.DAPR_INSTALL_URL }} -O - | /bin/bash
- name: Set up Go ${{ env.GOVER }}
if: env.DAPR_REF != '' || env.DAPR_CLI_REF != ''
uses: actions/setup-go@v1
with:
go-version: ${{ env.GOVER }}
- name: Checkout Dapr CLI repo to override dapr command.
uses: actions/checkout@v2
if: env.DAPR_CLI_REF != ''
with:
repository: dapr/cli
ref: ${{ env.DAPR_CLI_REF }}
path: cli
- name: Checkout Dapr repo to override daprd.
uses: actions/checkout@v2
if: env.DAPR_REF != ''
with:
repository: dapr/dapr
ref: ${{ env.DAPR_REF }}
path: dapr
- name: Build and override dapr cli with referenced commit.
if: env.DAPR_CLI_REF != ''
run: |
cd cli
make
sudo cp dist/linux_amd64/release/dapr /usr/local/bin/dapr
cd ..
- name: Initialize Dapr runtime ${{ env.DAPR_RUNTIME_VER }} - name: Initialize Dapr runtime ${{ env.DAPR_RUNTIME_VER }}
run: | run: |
sudo dapr init --runtime-version ${{ env.DAPR_RUNTIME_VER }} sudo dapr init --runtime-version ${{ env.DAPR_RUNTIME_VER }}
echo "Showing dapr version..." echo "Showing dapr version..."
dapr --version dapr --version
- name: Build and override daprd with referenced commit.
if: env.DAPR_REF != ''
run: |
cd dapr
make
sudo cp dist/linux_amd64/release/daprd /usr/local/bin/daprd
cd ..
- name: Install Local kafka using docker-compose - name: Install Local kafka using docker-compose
run: | run: |
docker-compose -f ./sdk-tests/deploy/local-test-kafka.yml up -d docker-compose -f ./sdk-tests/deploy/local-test-kafka.yml up -d

2
.gitignore vendored
View File

@ -41,6 +41,8 @@ hs_err_pid*
# Some other generated folders/files # Some other generated folders/files
**/components/redis.yaml **/components/redis.yaml
**/components/redis_messagebus.yaml **/components/redis_messagebus.yaml
**/components/statestore.yaml
**/components/messagebus.yaml
/docs/dapr-sdk-actors /docs/dapr-sdk-actors
/docs/dapr-sdk-autogen /docs/dapr-sdk-autogen
/docs/dapr-sdk /docs/dapr-sdk

View File

@ -9,3 +9,5 @@ spec:
value: localhost:6379 value: localhost:6379
- name: redisPassword - name: redisPassword
value: "" value: ""
- name: actorStateStore
value: "true"

View File

@ -23,6 +23,8 @@ public class StateClient {
public String message; public String message;
} }
private static final String STATE_STORE_NAME = "statestore";
private static final String KEY_NAME = "myKey"; private static final String KEY_NAME = "myKey";
/** /**
@ -36,17 +38,17 @@ public class StateClient {
MyClass myClass = new MyClass(); MyClass myClass = new MyClass();
myClass.message = message; myClass.message = message;
client.saveState(KEY_NAME, myClass).block(); client.saveState(STATE_STORE_NAME, KEY_NAME, myClass).block();
System.out.println("Saving class with message: " + message); System.out.println("Saving class with message: " + message);
Mono<State<MyClass>> retrievedMessageMono = client.getState(KEY_NAME, MyClass.class); Mono<State<MyClass>> retrievedMessageMono = client.getState(STATE_STORE_NAME, KEY_NAME, MyClass.class);
System.out.println("Retrieved class message from state: " + (retrievedMessageMono.block().getValue()).message); System.out.println("Retrieved class message from state: " + (retrievedMessageMono.block().getValue()).message);
System.out.println("Deleting state..."); System.out.println("Deleting state...");
Mono<Void> mono = client.deleteState(KEY_NAME); Mono<Void> mono = client.deleteState(STATE_STORE_NAME, KEY_NAME);
mono.block(); mono.block();
Mono<State<MyClass>> retrievedDeletedMessageMono = client.getState(KEY_NAME, MyClass.class); Mono<State<MyClass>> retrievedDeletedMessageMono = client.getState(STATE_STORE_NAME, KEY_NAME, MyClass.class);
System.out.println("Trying to retrieve deleted state: " + retrievedDeletedMessageMono.block().getValue()); System.out.println("Trying to retrieve deleted state: " + retrievedDeletedMessageMono.block().getValue());
} }

View File

@ -28,18 +28,21 @@ message InvokeServiceResponseEnvelope {
} }
message DeleteStateEnvelope { message DeleteStateEnvelope {
string key = 1; string storeName = 1;
string etag = 2; string key = 2;
StateOptions options = 3; string etag = 3;
StateOptions options = 4;
} }
message SaveStateEnvelope { message SaveStateEnvelope {
repeated StateRequest requests = 1; string storeName = 1;
repeated StateRequest requests = 2;
} }
message GetStateEnvelope { message GetStateEnvelope {
string key = 1; string storeName = 1;
string consistency = 2; string key = 2;
string consistency = 3;
} }
message GetStateResponseEnvelope { message GetStateResponseEnvelope {

View File

@ -11,6 +11,8 @@ import org.junit.AfterClass;
public abstract class BaseIT { public abstract class BaseIT {
protected static final String STATE_STORE_NAME = "statestore";
private static final Collection<DaprRun> DAPR_RUNS = new ArrayList<>(); private static final Collection<DaprRun> DAPR_RUNS = new ArrayList<>();
protected static DaprRun startDaprApp( protected static DaprRun startDaprApp(

View File

@ -62,13 +62,16 @@ public class PubSubIT extends BaseIT {
assertEquals(11, messages.size()); assertEquals(11, messages.size());
for (int i = 0; i < NUM_MESSAGES; i++) { for (int i = 0; i < NUM_MESSAGES; i++) {
assertTrue(messages.contains(String.format("This is message #%d", i)));
assertTrue(messages.get(i).startsWith("This is message "));
} }
byte[] result=new byte[] { 1 };
assertEquals(result.length, messages.get(10).getBytes().length); boolean foundByte = false;
assertEquals(result[0], messages.get(10).getBytes()[0]); for (String message : messages) {
if ((message.getBytes().length == 1) && (message.getBytes()[0] == 1)) {
foundByte = true;
}
}
assertTrue(foundByte);
}, 2000); }, 2000);
} }

View File

@ -62,12 +62,12 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create of the deferred call to DAPR to store the state //create of the deferred call to DAPR to store the state
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save action //execute the save action
saveResponse.block(); saveResponse.block();
//create of the deferred call to DAPR to get the state //create of the deferred call to DAPR to get the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//retrieve the state //retrieve the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -94,7 +94,7 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute save action to DAPR //execute save action to DAPR
saveResponse.block(); saveResponse.block();
@ -102,12 +102,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the sate without any etag or options //create deferred action to update the sate without any etag or options
saveResponse = daprClient.saveState(stateKey, null, data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the update action to DAPR //execute the update action to DAPR
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the action //Create deferred action to retrieve the action
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -126,12 +127,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -140,12 +142,12 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//create deferred action to delete the state //create deferred action to delete the state
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, null, null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, null, null);
//execute the delete action //execute the delete action
deleteResponse.block(); deleteResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
myDataResponse = response.block(); myDataResponse = response.block();
@ -166,12 +168,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -188,11 +191,11 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//Create deferred action to update the data using the correct etag //Create deferred action to update the data using the correct etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, null);
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//retrive the data wihout any etag //retrive the data wihout any etag
myDataResponse = response.block(); myDataResponse = response.block();
@ -206,7 +209,8 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B2", myDataResponse.getValue().getPropertyB());
} }
@Ignore("This test case is ignored because DAPR ignore the ETag is wrong when is sent from GRPC protocol, the execution continues and the state is updated.") @Ignore("This test case is ignored because DAPR ignore the ETag is wrong when is sent from GRPC protocol, the " +
"execution continues and the state is updated.")
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)
public void saveUpdateAndGetStateWithWrongEtag() { public void saveUpdateAndGetStateWithWrongEtag() {
final String stateKey = "keyToBeUpdatedWithWrongEtag"; final String stateKey = "keyToBeUpdatedWithWrongEtag";
@ -217,12 +221,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -239,11 +244,11 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//Create deferred action to update the data using the incorrect etag //Create deferred action to update the data using the incorrect etag
saveResponse = daprClient.saveState(stateKey, "99999999999999", data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "99999999999999", data, null);
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//retrive the data wihout any etag //retrive the data wihout any etag
myDataResponse = response.block(); myDataResponse = response.block();
@ -267,12 +272,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to get the state with the etag //Create deferred action to get the state with the etag
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the get state //execute the get state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -283,19 +289,20 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to delete an state sending the etag //Create deferred action to delete an state sending the etag
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, myDataResponse.getEtag(), null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), null);
//execute the delete of the state //execute the delete of the state
deleteResponse.block(); deleteResponse.block();
//Create deferred action to get the sate without an etag //Create deferred action to get the sate without an etag
response = daprClient.getState(new State(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
myDataResponse = response.block(); myDataResponse = response.block();
//Review that the response is null, because the state was deleted //Review that the response is null, because the state was deleted
assertNull(myDataResponse.getValue()); assertNull(myDataResponse.getValue());
} }
@Ignore("This test case is ignored because DAPR ignore if the ETag is wrong when is sent from GRPC protocol, the execution continues and the state is deleted.") @Ignore("This test case is ignored because DAPR ignore if the ETag is wrong when is sent from GRPC protocol, the " +
"execution continues and the state is deleted.")
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)
public void saveAndDeleteStateWithWrongEtag() { public void saveAndDeleteStateWithWrongEtag() {
final String stateKey = "myeKeyToBeDeletedWithWrongEtag"; final String stateKey = "myeKeyToBeDeletedWithWrongEtag";
@ -306,12 +313,13 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to get the state with the etag //Create deferred action to get the state with the etag
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the get state //execute the get state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -322,25 +330,27 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to delete an state sending the incorrect etag //Create deferred action to delete an state sending the incorrect etag
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, "99999999999", null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999999", null);
//execute the delete of the state, this should trhow an exception //execute the delete of the state, this should trhow an exception
deleteResponse.block(); deleteResponse.block();
//Create deferred action to get the sate without an etag //Create deferred action to get the sate without an etag
response = daprClient.getState(new State(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
myDataResponse = response.block(); myDataResponse = response.block();
//Review that the response is null, because the state was deleted //Review that the response is null, because the state was deleted
assertNull(myDataResponse.getValue()); assertNull(myDataResponse.getValue());
} }
@Ignore("This test case is ignored because it seems that DAPR using GRPC is ignoring the state options for consistency and concurrency.") @Ignore("This test case is ignored because it seems that DAPR using GRPC is ignoring the state options for " +
"consistency and concurrency.")
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)
public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() {
final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; final String stateKey = "keyToBeUpdatedWithEtagAndOptions";
//create option with concurrency with first writte and consistency of strong //create option with concurrency with first writte and consistency of strong
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, null); StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG,
StateOptions.Concurrency.FIRST_WRITE, null);
//create Dummy data //create Dummy data
@ -349,13 +359,14 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create state using stateOptions //create state using stateOptions
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, stateOptions);
//execute the save state //execute the save state
saveResponse.block(); saveResponse.block();
//crate deferred action to retrieve the state //crate deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options //execute the retrieve of the state using options
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -369,7 +380,7 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with options //create deferred action to update the action with options
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state //update the state
saveResponse.block(); saveResponse.block();
@ -377,11 +388,11 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("last write"); data.setPropertyA("last write");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with the same etag //create deferred action to update the action with the same etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//throws an exception, the state was already udpated //throws an exception, the state was already udpated
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block(); State<MyData> myLastDataResponse = response.block();
assertNotNull(myLastDataResponse.getEtag()); assertNotNull(myLastDataResponse.getEtag());
@ -397,7 +408,8 @@ public class GRPCStateClientIT extends BaseIT {
final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; final String stateKey = "keyToBeUpdatedWithEtagAndOptions";
//create option with concurrency with first writte and consistency of strong //create option with concurrency with first writte and consistency of strong
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE, null); StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE
, null);
//create Dummy data //create Dummy data
@ -406,13 +418,14 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create state using stateOptions //create state using stateOptions
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, stateOptions);
//execute the save state //execute the save state
saveResponse.block(); saveResponse.block();
//crate deferred action to retrieve the state //crate deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options //execute the retrieve of the state using options
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -426,7 +439,7 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with options //create deferred action to update the action with options
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state //update the state
saveResponse.block(); saveResponse.block();
@ -434,11 +447,11 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyA("last write"); data.setPropertyA("last write");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with the same etag //create deferred action to update the action with the same etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state without an error //update the state without an error
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block(); State<MyData> myLastDataResponse = response.block();
assertNotNull(myLastDataResponse.getEtag()); assertNotNull(myLastDataResponse.getEtag());
@ -452,7 +465,8 @@ public class GRPCStateClientIT extends BaseIT {
@Test(timeout = 13000) @Test(timeout = 13000)
public void saveDeleteWithRetry() { public void saveDeleteWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3, StateOptions.RetryPolicy.Pattern.LINEAR); StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3,
StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy); StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
@ -462,12 +476,12 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -479,7 +493,7 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, "99999999", stateOptions); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999", stateOptions);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
@ -499,7 +513,8 @@ public class GRPCStateClientIT extends BaseIT {
@Test(timeout = 13000) @Test(timeout = 13000)
public void saveUpdateWithRetry() { public void saveUpdateWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3, StateOptions.RetryPolicy.Pattern.LINEAR); StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3,
StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy); StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
@ -509,12 +524,12 @@ public class GRPCStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -526,7 +541,7 @@ public class GRPCStateClientIT extends BaseIT {
assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to save the sate //Create deferred action to save the sate
saveResponse = daprClient.saveState(stateKey, "9999999", data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "9999999", data, stateOptions);
//execute the save state action //execute the save state action
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();

View File

@ -33,6 +33,7 @@ public class HelloWorldClientIT extends BaseIT {
{ {
DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope
.newBuilder() .newBuilder()
.setStoreName(STATE_STORE_NAME)
.setKey(key) .setKey(key)
.build(); .build();
DaprProtos.GetStateResponseEnvelope response = client.getState(req); DaprProtos.GetStateResponseEnvelope response = client.getState(req);
@ -45,6 +46,7 @@ public class HelloWorldClientIT extends BaseIT {
{ {
DaprProtos.DeleteStateEnvelope req = DaprProtos.DeleteStateEnvelope DaprProtos.DeleteStateEnvelope req = DaprProtos.DeleteStateEnvelope
.newBuilder() .newBuilder()
.setStoreName(STATE_STORE_NAME)
.setKey(key) .setKey(key)
.build(); .build();
client.deleteState(req); client.deleteState(req);
@ -54,6 +56,7 @@ public class HelloWorldClientIT extends BaseIT {
{ {
DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope
.newBuilder() .newBuilder()
.setStoreName(STATE_STORE_NAME)
.setKey(key) .setKey(key)
.build(); .build();
DaprProtos.GetStateResponseEnvelope response = client.getState(req); DaprProtos.GetStateResponseEnvelope response = client.getState(req);

View File

@ -43,6 +43,7 @@ public class HelloWorldGrpcStateService {
.setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build()) .setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build())
.build(); .build();
SaveStateEnvelope state = SaveStateEnvelope.newBuilder() SaveStateEnvelope state = SaveStateEnvelope.newBuilder()
.setStoreName("statestore")
.addRequests(req) .addRequests(req)
.build(); .build();
client.saveState(state); client.saveState(state);

View File

@ -54,12 +54,12 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create of the deferred call to DAPR to store the state //create of the deferred call to DAPR to store the state
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save action //execute the save action
saveResponse.block(); saveResponse.block();
//create of the deferred call to DAPR to get the state //create of the deferred call to DAPR to get the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//retrieve the state //retrieve the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -86,7 +86,7 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute save action to DAPR //execute save action to DAPR
saveResponse.block(); saveResponse.block();
@ -94,12 +94,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the sate without any etag or options //create deferred action to update the sate without any etag or options
saveResponse = daprClient.saveState(stateKey, null, data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the update action to DAPR //execute the update action to DAPR
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the action //Create deferred action to retrieve the action
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -121,12 +122,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -135,12 +137,12 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//create deferred action to delete the state //create deferred action to delete the state
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, null, null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, null, null);
//execute the delete action //execute the delete action
deleteResponse.block(); deleteResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//execute the retrieve of the state //execute the retrieve of the state
myDataResponse = response.block(); myDataResponse = response.block();
@ -161,12 +163,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -183,11 +186,11 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//Create deferred action to update the data using the correct etag //Create deferred action to update the data using the correct etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, null);
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//retrive the data wihout any etag //retrive the data wihout any etag
myDataResponse = response.block(); myDataResponse = response.block();
@ -214,12 +217,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -236,11 +240,11 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//Create deferred action to update the data using the incorrect etag //Create deferred action to update the data using the incorrect etag
saveResponse = daprClient.saveState(stateKey, "99999999999999", data, null); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "99999999999999", data, null);
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null), MyData.class);
//retrive the data wihout any etag //retrive the data wihout any etag
myDataResponse = response.block(); myDataResponse = response.block();
@ -264,12 +268,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to get the state with the etag //Create deferred action to get the state with the etag
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the get state //execute the get state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -280,12 +285,12 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to delete an state sending the etag //Create deferred action to delete an state sending the etag
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, myDataResponse.getEtag(), null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), null);
//execute the delete of the state //execute the delete of the state
deleteResponse.block(); deleteResponse.block();
//Create deferred action to get the sate without an etag //Create deferred action to get the sate without an etag
response = daprClient.getState(new State(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
myDataResponse = response.block(); myDataResponse = response.block();
//Review that the response is null, because the state was deleted //Review that the response is null, because the state was deleted
@ -304,12 +309,13 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A"); data.setPropertyA("data in property A");
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to get the state with the etag //Create deferred action to get the state with the etag
Mono<State<MyData>> response = daprClient.getState(new State<MyData>(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State<MyData>(stateKey, null, null),
MyData.class);
//execute the get state //execute the get state
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -320,12 +326,12 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to delete an state sending the incorrect etag //Create deferred action to delete an state sending the incorrect etag
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, "99999999999", null); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999999", null);
//execute the delete of the state, this should trhow an exception //execute the delete of the state, this should trhow an exception
deleteResponse.block(); deleteResponse.block();
//Create deferred action to get the sate without an etag //Create deferred action to get the sate without an etag
response = daprClient.getState(new State(stateKey, null, null), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
myDataResponse = response.block(); myDataResponse = response.block();
//Review that the response is null, because the state was deleted //Review that the response is null, because the state was deleted
@ -337,7 +343,8 @@ public class HttpStateClientIT extends BaseIT {
final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; final String stateKey = "keyToBeUpdatedWithEtagAndOptions";
//create option with concurrency with first writte and consistency of strong //create option with concurrency with first writte and consistency of strong
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, null); StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG,
StateOptions.Concurrency.FIRST_WRITE, null);
//create dapr client //create dapr client
DaprClient daprClient = buildDaprClient(); DaprClient daprClient = buildDaprClient();
@ -347,13 +354,14 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create state using stateOptions //create state using stateOptions
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, stateOptions);
//execute the save state //execute the save state
saveResponse.block(); saveResponse.block();
//crate deferred action to retrieve the state //crate deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options //execute the retrieve of the state using options
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -367,7 +375,7 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with options //create deferred action to update the action with options
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state //update the state
saveResponse.block(); saveResponse.block();
@ -375,11 +383,11 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("last write"); data.setPropertyA("last write");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with the same etag //create deferred action to update the action with the same etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//throws an exception, the state was already udpated //throws an exception, the state was already udpated
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block(); State<MyData> myLastDataResponse = response.block();
Assert.assertNotNull(myLastDataResponse.getEtag()); Assert.assertNotNull(myLastDataResponse.getEtag());
@ -395,7 +403,8 @@ public class HttpStateClientIT extends BaseIT {
final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; final String stateKey = "keyToBeUpdatedWithEtagAndOptions";
//create option with concurrency with first writte and consistency of strong //create option with concurrency with first writte and consistency of strong
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE, null); StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE
, null);
//create dapr client //create dapr client
DaprClient daprClient = buildDaprClient(); DaprClient daprClient = buildDaprClient();
@ -405,13 +414,14 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//create state using stateOptions //create state using stateOptions
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, stateOptions);
//execute the save state //execute the save state
saveResponse.block(); saveResponse.block();
//crate deferred action to retrieve the state //crate deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options //execute the retrieve of the state using options
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -425,7 +435,7 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("data in property A2"); data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with options //create deferred action to update the action with options
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state //update the state
saveResponse.block(); saveResponse.block();
@ -433,11 +443,11 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyA("last write"); data.setPropertyA("last write");
data.setPropertyB("data in property B2"); data.setPropertyB("data in property B2");
//create deferred action to update the action with the same etag //create deferred action to update the action with the same etag
saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//update the state without an error //update the state without an error
saveResponse.block(); saveResponse.block();
response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block(); State<MyData> myLastDataResponse = response.block();
Assert.assertNotNull(myLastDataResponse.getEtag()); Assert.assertNotNull(myLastDataResponse.getEtag());
@ -451,7 +461,8 @@ public class HttpStateClientIT extends BaseIT {
@Test(timeout = 13000) @Test(timeout = 13000)
public void saveDeleteWithRetry() { public void saveDeleteWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3, StateOptions.RetryPolicy.Pattern.LINEAR); StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(3), 3,
StateOptions.RetryPolicy.Pattern.LINEAR);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy); StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
//create DAPR client //create DAPR client
@ -462,12 +473,12 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -479,7 +490,7 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
Mono<Void> deleteResponse = daprClient.deleteState(stateKey, "99999999", stateOptions); Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999", stateOptions);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
@ -499,7 +510,8 @@ public class HttpStateClientIT extends BaseIT {
@Test(timeout = 13000) @Test(timeout = 13000)
public void saveUpdateWithRetry() { public void saveUpdateWithRetry() {
final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry";
StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3, StateOptions.RetryPolicy.Pattern.EXPONENTIAL); StateOptions.RetryPolicy retryPolicy = new StateOptions.RetryPolicy(Duration.ofSeconds(4), 3,
StateOptions.RetryPolicy.Pattern.EXPONENTIAL);
StateOptions stateOptions = new StateOptions(null, null, retryPolicy); StateOptions stateOptions = new StateOptions(null, null, retryPolicy);
//create DAPR client //create DAPR client
@ -510,12 +522,12 @@ public class HttpStateClientIT extends BaseIT {
data.setPropertyB("data in property B"); data.setPropertyB("data in property B");
//Create deferred action to save the sate //Create deferred action to save the sate
Mono<Void> saveResponse = daprClient.saveState(stateKey, null, data, null); Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action //execute the save state action
saveResponse.block(); saveResponse.block();
//Create deferred action to retrieve the state //Create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(new State(stateKey, null, null), MyData.class); Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, null), MyData.class);
//execute the action for retrieve the state and the etag //execute the action for retrieve the state and the etag
State<MyData> myDataResponse = response.block(); State<MyData> myDataResponse = response.block();
@ -527,7 +539,7 @@ public class HttpStateClientIT extends BaseIT {
Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//Create deferred action to save the sate //Create deferred action to save the sate
saveResponse = daprClient.saveState(stateKey, "9999999", data, stateOptions); saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "9999999", data, stateOptions);
//execute the save state action //execute the save state action
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();

View File

@ -148,26 +148,29 @@ public interface DaprClient {
/** /**
* Retrieve a State based on their key. * Retrieve a State based on their key.
* *
* @param stateStoreName The name of the state store.
* @param state State to be re-retrieved. * @param state State to be re-retrieved.
* @param clazz The Type of State needed as return. * @param clazz The Type of State needed as return.
* @param <T> The Type of the return. * @param <T> The Type of the return.
* @return A Mono Plan for the requested State. * @return A Mono Plan for the requested State.
*/ */
<T> Mono<State<T>> getState(State<T> state, Class<T> clazz); <T> Mono<State<T>> getState(String stateStoreName, State<T> state, Class<T> clazz);
/** /**
* Retrieve a State based on their key. * Retrieve a State based on their key.
* *
* @param stateStoreName The name of the state store.
* @param key The key of the State to be retrieved. * @param key The key of the State to be retrieved.
* @param clazz The Type of State needed as return. * @param clazz The Type of State needed as return.
* @param <T> The Type of the return. * @param <T> The Type of the return.
* @return A Mono Plan for the requested State. * @return A Mono Plan for the requested State.
*/ */
<T> Mono<State<T>> getState(String key, Class<T> clazz); <T> Mono<State<T>> getState(String stateStoreName, String key, Class<T> clazz);
/** /**
* Retrieve a State based on their key. * Retrieve a State based on their key.
* *
* @param stateStoreName The name of the state store.
* @param key The key of the State to be retrieved. * @param key The key of the State to be retrieved.
* @param etag Optional etag for conditional get * @param etag Optional etag for conditional get
* @param options Optional settings for retrieve operation. * @param options Optional settings for retrieve operation.
@ -175,51 +178,56 @@ public interface DaprClient {
* @param <T> The Type of the return. * @param <T> The Type of the return.
* @return A Mono Plan for the requested State. * @return A Mono Plan for the requested State.
*/ */
<T> Mono<State<T>> getState(String key, String etag, StateOptions options, Class<T> clazz); <T> Mono<State<T>> getState(String stateStoreName, String key, String etag, StateOptions options, Class<T> clazz);
/** /**
* Save/Update a list of states. * Save/Update a list of states.
* *
* @param states the States to be saved. * @param stateStoreName The name of the state store.
* @param states The States to be saved.
* @return a Mono plan of type Void. * @return a Mono plan of type Void.
*/ */
Mono<Void> saveStates(List<State<?>> states); Mono<Void> saveStates(String stateStoreName, List<State<?>> states);
/** /**
* Save/Update a state. * Save/Update a state.
* *
* @param key the key of the state. * @param stateStoreName The name of the state store.
* @param value the value of the state. * @param key The key of the state.
* @param value The value of the state.
* @return a Mono plan of type Void. * @return a Mono plan of type Void.
*/ */
Mono<Void> saveState(String key, Object value); Mono<Void> saveState(String stateStoreName, String key, Object value);
/** /**
* Save/Update a state. * Save/Update a state.
* *
* @param key the key of the state. * @param stateStoreName The name of the state store.
* @param etag the etag to be used. * @param key The key of the state.
* @param value the value of the state. * @param etag The etag to be used.
* @param options the Options to use for each state. * @param value The value of the state.
* @param options The Options to use for each state.
* @return a Mono plan of type Void. * @return a Mono plan of type Void.
*/ */
Mono<Void> saveState(String key, String etag, Object value, StateOptions options); Mono<Void> saveState(String stateStoreName, String key, String etag, Object value, StateOptions options);
/** /**
* Delete a state. * Delete a state.
* *
* @param stateStoreName The name of the state store.
* @param key The key of the State to be removed. * @param key The key of the State to be removed.
* @return a Mono plan of type Void. * @return a Mono plan of type Void.
*/ */
Mono<Void> deleteState(String key); Mono<Void> deleteState(String stateStoreName, String key);
/** /**
* Delete a state. * Delete a state.
* *
* @param stateStoreName The name of the state store.
* @param key The key of the State to be removed. * @param key The key of the State to be removed.
* @param etag Optional etag for conditional delete. * @param etag Optional etag for conditional delete.
* @param options Optional settings for state operation. * @param options Optional settings for state operation.
* @return a Mono plan of type Void. * @return a Mono plan of type Void.
*/ */
Mono<Void> deleteState(String key, String etag, StateOptions options); Mono<Void> deleteState(String stateStoreName, String key, String etag, StateOptions options);
} }

View File

@ -210,25 +210,33 @@ public class DaprClientGrpc implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(State<T> state, Class<T> clazz) { public <T> Mono<State<T>> getState(String stateStoreName, State<T> state, Class<T> clazz) {
return this.getState(state.getKey(), state.getEtag(), state.getOptions(), clazz); return this.getState(stateStoreName, state.getKey(), state.getEtag(), state.getOptions(), clazz);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(String key, Class<T> clazz) { public <T> Mono<State<T>> getState(String stateStoreName, String key, Class<T> clazz) {
return this.getState(key, null, null, clazz); return this.getState(stateStoreName, key, null, null, clazz);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(String key, String etag, StateOptions options, Class<T> clazz) { public <T> Mono<State<T>> getState(
String stateStoreName, String key, String etag, StateOptions options, Class<T> clazz) {
try { try {
if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("State store name cannot be null or empty.");
}
if ((key == null) || (key.trim().isEmpty())) {
throw new IllegalArgumentException("Key cannot be null or empty.");
}
DaprProtos.GetStateEnvelope.Builder builder = DaprProtos.GetStateEnvelope.newBuilder() DaprProtos.GetStateEnvelope.Builder builder = DaprProtos.GetStateEnvelope.newBuilder()
.setStoreName(stateStoreName)
.setKey(key); .setKey(key);
if (options != null && options.getConsistency() != null) { if (options != null && options.getConsistency() != null) {
builder.setConsistency(options.getConsistency().getValue()); builder.setConsistency(options.getConsistency().getValue());
@ -267,9 +275,13 @@ public class DaprClientGrpc implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveStates(List<State<?>> states) { public Mono<Void> saveStates(String stateStoreName, List<State<?>> states) {
try { try {
if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("State store name cannot be null or empty.");
}
DaprProtos.SaveStateEnvelope.Builder builder = DaprProtos.SaveStateEnvelope.newBuilder(); DaprProtos.SaveStateEnvelope.Builder builder = DaprProtos.SaveStateEnvelope.newBuilder();
builder.setStoreName(stateStoreName);
for (State state : states) { for (State state : states) {
builder.addRequests(buildStateRequest(state).build()); builder.addRequests(buildStateRequest(state).build());
} }
@ -342,33 +354,40 @@ public class DaprClientGrpc implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveState(String key, Object value) { public Mono<Void> saveState(String stateStoreName, String key, Object value) {
return this.saveState(key, null, value, null); return this.saveState(stateStoreName, key, null, value, null);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveState(String key, String etag, Object value, StateOptions options) { public Mono<Void> saveState(String stateStoreName, String key, String etag, Object value, StateOptions options) {
State<?> state = new State<>(value, key, etag, options); State<?> state = new State<>(value, key, etag, options);
return this.saveStates(Arrays.asList(state)); return this.saveStates(stateStoreName, Arrays.asList(state));
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> deleteState(String key) { public Mono<Void> deleteState(String stateStoreName, String key) {
return this.deleteState(key, null, null); return this.deleteState(stateStoreName, key, null, null);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> deleteState(String key, String etag, StateOptions options) { public Mono<Void> deleteState(String stateStoreName, String key, String etag, StateOptions options) {
try { try {
if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("State store name cannot be null or empty.");
}
if ((key == null) || (key.trim().isEmpty())) {
throw new IllegalArgumentException("Key cannot be null or empty.");
}
DaprProtos.StateOptions.Builder optionBuilder = null; DaprProtos.StateOptions.Builder optionBuilder = null;
if (options != null) { if (options != null) {
optionBuilder = DaprProtos.StateOptions.newBuilder(); optionBuilder = DaprProtos.StateOptions.newBuilder();
@ -402,6 +421,7 @@ public class DaprClientGrpc implements DaprClient {
} }
} }
DaprProtos.DeleteStateEnvelope.Builder builder = DaprProtos.DeleteStateEnvelope.newBuilder() DaprProtos.DeleteStateEnvelope.Builder builder = DaprProtos.DeleteStateEnvelope.newBuilder()
.setStoreName(stateStoreName)
.setKey(key); .setKey(key);
if (etag != null) { if (etag != null) {
builder.setEtag(etag); builder.setEtag(etag);

View File

@ -268,26 +268,30 @@ public class DaprClientHttp implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(State<T> state, Class<T> clazz) { public <T> Mono<State<T>> getState(String stateStoreName, State<T> state, Class<T> clazz) {
return this.getState(state.getKey(), state.getEtag(), state.getOptions(), clazz); return this.getState(stateStoreName, state.getKey(), state.getEtag(), state.getOptions(), clazz);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(String key, Class<T> clazz) { public <T> Mono<State<T>> getState(String stateStoreName, String key, Class<T> clazz) {
return this.getState(key, null, null, clazz); return this.getState(stateStoreName, key, null, null, clazz);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public <T> Mono<State<T>> getState(String key, String etag, StateOptions options, Class<T> clazz) { public <T> Mono<State<T>> getState(
String stateStoreName, String key, String etag, StateOptions options, Class<T> clazz) {
try { try {
if (key == null) { if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("Name cannot be null or empty."); throw new IllegalArgumentException("State store name cannot be null or empty.");
}
if ((key == null) || (key.trim().isEmpty())) {
throw new IllegalArgumentException("Key cannot be null or empty.");
} }
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
if (etag != null && !etag.trim().isEmpty()) { if (etag != null && !etag.trim().isEmpty()) {
@ -295,6 +299,8 @@ public class DaprClientHttp implements DaprClient {
} }
StringBuilder url = new StringBuilder(Constants.STATE_PATH) StringBuilder url = new StringBuilder(Constants.STATE_PATH)
.append("/")
.append(stateStoreName)
.append("/") .append("/")
.append(key); .append(key);
Map<String, String> urlParameters = Optional.ofNullable(options) Map<String, String> urlParameters = Optional.ofNullable(options)
@ -319,8 +325,11 @@ public class DaprClientHttp implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveStates(List<State<?>> states) { public Mono<Void> saveStates(String stateStoreName, List<State<?>> states) {
try { try {
if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("State store name cannot be null or empty.");
}
if (states == null || states.isEmpty()) { if (states == null || states.isEmpty()) {
return Mono.empty(); return Mono.empty();
} }
@ -330,7 +339,7 @@ public class DaprClientHttp implements DaprClient {
if (etag != null && !etag.trim().isEmpty()) { if (etag != null && !etag.trim().isEmpty()) {
headers.put(Constants.HEADER_HTTP_ETAG_ID, etag); headers.put(Constants.HEADER_HTTP_ETAG_ID, etag);
} }
final String url = Constants.STATE_PATH; final String url = Constants.STATE_PATH + "/" + stateStoreName;
List<State<Object>> internalStateObjects = new ArrayList<>(states.size()); List<State<Object>> internalStateObjects = new ArrayList<>(states.size());
for (State state : states) { for (State state : states) {
if (state == null) { if (state == null) {
@ -356,41 +365,44 @@ public class DaprClientHttp implements DaprClient {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveState(String key, Object value) { public Mono<Void> saveState(String stateStoreName, String key, Object value) {
return this.saveState(key, null, value, null); return this.saveState(stateStoreName, key, null, value, null);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> saveState(String key, String etag, Object value, StateOptions options) { public Mono<Void> saveState(String stateStoreName, String key, String etag, Object value, StateOptions options) {
return Mono.fromSupplier(() -> new State<>(value, key, etag, options)) return Mono.fromSupplier(() -> new State<>(value, key, etag, options))
.flatMap(state -> saveStates(Arrays.asList(state))); .flatMap(state -> saveStates(stateStoreName, Arrays.asList(state)));
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> deleteState(String key) { public Mono<Void> deleteState(String stateStoreName, String key) {
return this.deleteState(key, null, null); return this.deleteState(stateStoreName, key, null, null);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Mono<Void> deleteState(String key, String etag, StateOptions options) { public Mono<Void> deleteState(String stateStoreName, String key, String etag, StateOptions options) {
try { try {
if (key == null || key.trim().isEmpty()) { if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) {
throw new IllegalArgumentException("Name cannot be null or empty."); throw new IllegalArgumentException("State store name cannot be null or empty.");
}
if ((key == null) || (key.trim().isEmpty())) {
throw new IllegalArgumentException("Key cannot be null or empty.");
} }
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
if (etag != null && !etag.trim().isEmpty()) { if (etag != null && !etag.trim().isEmpty()) {
headers.put(Constants.HEADER_HTTP_ETAG_ID, etag); headers.put(Constants.HEADER_HTTP_ETAG_ID, etag);
} }
String url = Constants.STATE_PATH + "/" + key; String url = Constants.STATE_PATH + "/" + stateStoreName + "/" + key;
Map<String, String> urlParameters = Optional.ofNullable(options) Map<String, String> urlParameters = Optional.ofNullable(options)
.map(stateOptions -> stateOptions.getStateOptionsAsMap()) .map(stateOptions -> stateOptions.getStateOptionsAsMap())
.orElse(new HashMap<>()); .orElse(new HashMap<>());

View File

@ -35,6 +35,8 @@ import static org.mockito.Mockito.*;
public class DaprClientGrpcTest { public class DaprClientGrpcTest {
private static final String STATE_STORE_NAME = "MyStateStore";
private DaprGrpc.DaprFutureStub client; private DaprGrpc.DaprFutureStub client;
private DaprClientGrpc adapter; private DaprClientGrpc adapter;
private ObjectSerializer serializer; private ObjectSerializer serializer;
@ -434,7 +436,7 @@ public class DaprClientGrpcTest {
public void getStateExceptionThrownTest() { public void getStateExceptionThrownTest() {
when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))).thenThrow(RuntimeException.class); when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))).thenThrow(RuntimeException.class);
State<String> key = buildStateKey(null, "Key1", "ETag1", null); State<String> key = buildStateKey(null, "Key1", "ETag1", null);
Mono<State<String>> result = adapter.getState(key, String.class); Mono<State<String>> result = adapter.getState(STATE_STORE_NAME, key, String.class);
result.block(); result.block();
} }
@ -448,7 +450,7 @@ public class DaprClientGrpcTest {
when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> key = buildStateKey(null, "Key1", "ETag1", null); State<String> key = buildStateKey(null, "Key1", "ETag1", null);
Mono<State<String>> result = adapter.getState(key, String.class); Mono<State<String>> result = adapter.getState(STATE_STORE_NAME, key, String.class);
settableFuture.setException(ex); settableFuture.setException(ex);
result.block(); result.block();
} }
@ -466,7 +468,7 @@ public class DaprClientGrpcTest {
when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> keyRequest = buildStateKey(null, key, etag, null); State<String> keyRequest = buildStateKey(null, key, etag, null);
Mono<State<String>> result = adapter.getState(keyRequest, String.class); Mono<State<String>> result = adapter.getState(STATE_STORE_NAME, keyRequest, String.class);
settableFuture.set(responseEnvelope); settableFuture.set(responseEnvelope);
assertEquals(expectedState, result.block()); assertEquals(expectedState, result.block());
} }
@ -489,7 +491,7 @@ public class DaprClientGrpcTest {
addCallback(settableFuture, callback, directExecutor()); addCallback(settableFuture, callback, directExecutor());
when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
Mono<State<MyObject>> result = adapter.getState(keyRequest, MyObject.class); Mono<State<MyObject>> result = adapter.getState(STATE_STORE_NAME, keyRequest, MyObject.class);
settableFuture.set(responseEnvelope); settableFuture.set(responseEnvelope);
assertEquals(expectedState, result.block()); assertEquals(expectedState, result.block());
} }
@ -512,7 +514,7 @@ public class DaprClientGrpcTest {
addCallback(settableFuture, callback, directExecutor()); addCallback(settableFuture, callback, directExecutor());
when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
Mono<State<MyObject>> result = adapter.getState(keyRequest, MyObject.class); Mono<State<MyObject>> result = adapter.getState(STATE_STORE_NAME, keyRequest, MyObject.class);
settableFuture.set(responseEnvelope); settableFuture.set(responseEnvelope);
assertEquals(expectedState, result.block()); assertEquals(expectedState, result.block());
} }
@ -521,7 +523,7 @@ public class DaprClientGrpcTest {
public void deleteStateExceptionThrowTest() { public void deleteStateExceptionThrowTest() {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))).thenThrow(RuntimeException.class); when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))).thenThrow(RuntimeException.class);
State<String> key = buildStateKey(null, "Key1", "ETag1", null); State<String> key = buildStateKey(null, "Key1", "ETag1", null);
Mono<Void> result = adapter.deleteState(key.getKey(), key.getEtag(), key.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, key.getKey(), key.getEtag(), key.getOptions());
result.block(); result.block();
} }
@ -535,7 +537,7 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> key = buildStateKey(null, "Key1", "ETag1", null); State<String> key = buildStateKey(null, "Key1", "ETag1", null);
Mono<Void> result = adapter.deleteState(key.getKey(), key.getEtag(), key.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, key.getKey(), key.getEtag(), key.getOptions());
settableFuture.setException(ex); settableFuture.setException(ex);
result.block(); result.block();
} }
@ -550,7 +552,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, null); State<String> stateKey = buildStateKey(null, key, etag, null);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -568,7 +571,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -586,7 +590,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -604,7 +609,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -622,7 +628,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -640,7 +647,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -658,7 +666,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -676,7 +685,8 @@ public class DaprClientGrpcTest {
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFuture); .thenReturn(settableFuture);
State<String> stateKey = buildStateKey(null, key, etag, options); State<String> stateKey = buildStateKey(null, key, etag, options);
Mono<Void> result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); Mono<Void> result = adapter.deleteState(STATE_STORE_NAME, stateKey.getKey(), stateKey.getEtag(),
stateKey.getOptions());
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -688,7 +698,7 @@ public class DaprClientGrpcTest {
String etag = "ETag1"; String etag = "ETag1";
String value = "State value"; String value = "State value";
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenThrow(RuntimeException.class); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenThrow(RuntimeException.class);
Mono<Void> result = adapter.saveState(key, etag, value, null); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, null);
result.block(); result.block();
} }
@ -702,7 +712,7 @@ public class DaprClientGrpcTest {
MockCallback<Empty> callback = new MockCallback<>(ex); MockCallback<Empty> callback = new MockCallback<>(ex);
addCallback(settableFuture, callback, directExecutor()); addCallback(settableFuture, callback, directExecutor());
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
Mono<Void> result = adapter.saveState(key, etag, value, null); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, null);
settableFuture.setException(ex); settableFuture.setException(ex);
result.block(); result.block();
} }
@ -716,7 +726,7 @@ public class DaprClientGrpcTest {
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build()); MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
addCallback(settableFuture, callback, directExecutor()); addCallback(settableFuture, callback, directExecutor());
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
Mono<Void> result = adapter.saveState(key, etag, value, null); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, null);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -733,7 +743,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE,
Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -750,7 +760,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(null, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(null, StateOptions.Concurrency.FIRST_WRITE,
Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -767,7 +777,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null,
Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -784,7 +794,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE,
null, null, null); null, null, null);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -801,7 +811,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE,
null, 1, StateOptions.RetryPolicy.Pattern.LINEAR); null, 1, StateOptions.RetryPolicy.Pattern.LINEAR);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -818,7 +828,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE,
Duration.ofDays(100), null, StateOptions.RetryPolicy.Pattern.LINEAR); Duration.ofDays(100), null, StateOptions.RetryPolicy.Pattern.LINEAR);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -835,7 +845,7 @@ public class DaprClientGrpcTest {
when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture);
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE,
Duration.ofDays(100), 1, null); Duration.ofDays(100), 1, null);
Mono<Void> result = adapter.saveState(key, etag, value, options); Mono<Void> result = adapter.saveState(STATE_STORE_NAME, key, etag, value, options);
settableFuture.set(Empty.newBuilder().build()); settableFuture.set(Empty.newBuilder().build());
result.block(); result.block();
assertTrue(callback.wasCalled); assertTrue(callback.wasCalled);
@ -848,9 +858,9 @@ public class DaprClientGrpcTest {
/** /**
* The purpose of this test is to show that it doesn't matter when the client is called, the actual coll to DAPR * The purpose of this test is to show that it doesn't matter when the client is called, the actual coll to DAPR
* will be done when the output Mono response call the Mono.block method. * will be done when the output Mono response call the Mono.block method.
* Like for instanche if you call getState, withouth blocking for the response, and then call delete for the same state * Like for instance if you call getState, without blocking for the response, and then call delete for the same
* you just retrived but block for the delete response, when later you block for the response of the getState, you will * state you just retrieved but block for the delete response, when later you block for the response of the getState,
* not found the state. * you will not find the state.
* <p>This test will execute the following flow:</p> * <p>This test will execute the following flow:</p>
* <ol> * <ol>
* <li>Exeucte client getState for Key=key1</li> * <li>Exeucte client getState for Key=key1</li>
@ -861,7 +871,8 @@ public class DaprClientGrpcTest {
* <li>Block for deleteState call.</li> * <li>Block for deleteState call.</li>
* <li>Block for getState for Key=key2 and Assert they 2 was not found.</li> * <li>Block for getState for Key=key2 and Assert they 2 was not found.</li>
* </ol> * </ol>
* @throws Exception - Test will fail if any unexpected exception is being thrown *
* @throws Exception - Test will fail if any unexpected exception is being thrown.
*/ */
@Test @Test
@ -877,17 +888,18 @@ public class DaprClientGrpcTest {
futuresMap.put(key2, buildFutureGetStateEnvelop(expectedValue2, etag)); futuresMap.put(key2, buildFutureGetStateEnvelop(expectedValue2, etag));
when(client.getState(argThat(new GetStateEnvelopeKeyMatcher(key1)))).thenReturn(futuresMap.get(key1)); when(client.getState(argThat(new GetStateEnvelopeKeyMatcher(key1)))).thenReturn(futuresMap.get(key1));
State<String> keyRequest1 = buildStateKey(null, key1, etag, null); State<String> keyRequest1 = buildStateKey(null, key1, etag, null);
Mono<State<String>> resultGet1 = adapter.getState(keyRequest1, String.class); Mono<State<String>> resultGet1 = adapter.getState(STATE_STORE_NAME, keyRequest1, String.class);
assertEquals(expectedState1, resultGet1.block()); assertEquals(expectedState1, resultGet1.block());
State<String> keyRequest2 = buildStateKey(null, key2, etag, null); State<String> keyRequest2 = buildStateKey(null, key2, etag, null);
Mono<State<String>> resultGet2 = adapter.getState(keyRequest2, String.class); Mono<State<String>> resultGet2 = adapter.getState(STATE_STORE_NAME, keyRequest2, String.class);
SettableFuture<Empty> settableFutureDelete = SettableFuture.create(); SettableFuture<Empty> settableFutureDelete = SettableFuture.create();
MockCallback<Empty> callbackDelete = new MockCallback<>(Empty.newBuilder().build()); MockCallback<Empty> callbackDelete = new MockCallback<>(Empty.newBuilder().build());
addCallback(settableFutureDelete, callbackDelete, directExecutor()); addCallback(settableFutureDelete, callbackDelete, directExecutor());
when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class)))
.thenReturn(settableFutureDelete); .thenReturn(settableFutureDelete);
Mono<Void> resultDelete = adapter.deleteState(keyRequest2.getKey(), keyRequest2.getEtag(), keyRequest2.getOptions()); Mono<Void> resultDelete = adapter.deleteState(STATE_STORE_NAME, keyRequest2.getKey(), keyRequest2.getEtag(),
keyRequest2.getOptions());
settableFutureDelete.set(Empty.newBuilder().build()); settableFutureDelete.set(Empty.newBuilder().build());
resultDelete.block(); resultDelete.block();
assertTrue(callbackDelete.wasCalled); assertTrue(callbackDelete.wasCalled);
@ -916,7 +928,8 @@ public class DaprClientGrpcTest {
} }
private StateOptions buildStateOptions(StateOptions.Consistency consistency, StateOptions.Concurrency concurrency, private StateOptions buildStateOptions(StateOptions.Consistency consistency, StateOptions.Concurrency concurrency,
Duration interval, Integer threshold, StateOptions.RetryPolicy.Pattern pattern) { Duration interval, Integer threshold,
StateOptions.RetryPolicy.Pattern pattern) {
StateOptions.RetryPolicy retryPolicy = null; StateOptions.RetryPolicy retryPolicy = null;
if (interval != null || threshold != null || pattern != null) { if (interval != null || threshold != null || pattern != null) {

View File

@ -22,6 +22,8 @@ import static org.mockito.Mockito.mock;
public class DaprClientHttpTest { public class DaprClientHttpTest {
private static final String STATE_STORE_NAME = "MyStateStore";
private DaprClientHttp daprClientHttp; private DaprClientHttp daprClientHttp;
private DaprHttp daprHttp; private DaprHttp daprHttp;
@ -30,7 +32,8 @@ public class DaprClientHttpTest {
private MockInterceptor mockInterceptor; private MockInterceptor mockInterceptor;
private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; private final String EXPECTED_RESULT =
"{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -215,14 +218,14 @@ public class DaprClientHttpTest {
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions); State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
State<String> stateKeyNull = new State("value", null, "etag", stateOptions); State<String> stateKeyNull = new State("value", null, "etag", stateOptions);
mockInterceptor.addRule() mockInterceptor.addRule()
.get("http://localhost:3000/v1.0/state/key") .get("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond("\"" + EXPECTED_RESULT + "\""); .respond("\"" + EXPECTED_RESULT + "\"");
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.getState(stateKeyNull, String.class).block(); daprClientHttp.getState(STATE_STORE_NAME, stateKeyNull, String.class).block();
}); });
Mono<State<String>> mono = daprClientHttp.getState(stateKeyValue, String.class); Mono<State<String>> mono = daprClientHttp.getState(STATE_STORE_NAME, stateKeyValue, String.class);
assertEquals(mono.block().getKey(), "key"); assertEquals(mono.block().getKey(), "key");
} }
@ -230,11 +233,11 @@ public class DaprClientHttpTest {
public void getStatesEmptyEtag() { public void getStatesEmptyEtag() {
State<String> stateEmptyEtag = new State("value", "key", "", null); State<String> stateEmptyEtag = new State("value", "key", "", null);
mockInterceptor.addRule() mockInterceptor.addRule()
.get("http://localhost:3000/v1.0/state/key") .get("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond("\"" + EXPECTED_RESULT + "\""); .respond("\"" + EXPECTED_RESULT + "\"");
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<State<String>> monoEmptyEtag = daprClientHttp.getState(stateEmptyEtag, String.class); Mono<State<String>> monoEmptyEtag = daprClientHttp.getState(STATE_STORE_NAME, stateEmptyEtag, String.class);
assertEquals(monoEmptyEtag.block().getKey(), "key"); assertEquals(monoEmptyEtag.block().getKey(), "key");
} }
@ -242,11 +245,11 @@ public class DaprClientHttpTest {
public void getStatesNullEtag() { public void getStatesNullEtag() {
State<String> stateNullEtag = new State("value", "key", null, null); State<String> stateNullEtag = new State("value", "key", null, null);
mockInterceptor.addRule() mockInterceptor.addRule()
.get("http://localhost:3000/v1.0/state/key") .get("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond("\"" + EXPECTED_RESULT + "\""); .respond("\"" + EXPECTED_RESULT + "\"");
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<State<String>> monoNullEtag = daprClientHttp.getState(stateNullEtag, String.class); Mono<State<String>> monoNullEtag = daprClientHttp.getState(STATE_STORE_NAME, stateNullEtag, String.class);
assertEquals(monoNullEtag.block().getKey(), "key"); assertEquals(monoNullEtag.block().getKey(), "key");
} }
@ -255,11 +258,11 @@ public class DaprClientHttpTest {
State<String> stateKeyValue = new State("value", "key", "etag", null); State<String> stateKeyValue = new State("value", "key", "etag", null);
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue); List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
mockInterceptor.addRule() mockInterceptor.addRule()
.post("http://localhost:3000/v1.0/state") .post("http://localhost:3000/v1.0/state/MyStateStore")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.saveStates(stateKeyValueList); Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -268,13 +271,13 @@ public class DaprClientHttpTest {
State<String> stateKeyValue = new State("value", "key", "", null); State<String> stateKeyValue = new State("value", "key", "", null);
List<State<?>> stateKeyValueList = new ArrayList(); List<State<?>> stateKeyValueList = new ArrayList();
mockInterceptor.addRule() mockInterceptor.addRule()
.post("http://localhost:3000/v1.0/state") .post("http://localhost:3000/v1.0/state/MyStateStore")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.saveStates(null); Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, null);
assertNull(mono.block()); assertNull(mono.block());
Mono<Void> mono1 = daprClientHttp.saveStates(stateKeyValueList); Mono<Void> mono1 = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
assertNull(mono1.block()); assertNull(mono1.block());
} }
@ -283,11 +286,11 @@ public class DaprClientHttpTest {
State<String> stateKeyValue = new State("value", "key", null, null); State<String> stateKeyValue = new State("value", "key", null, null);
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue); List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
mockInterceptor.addRule() mockInterceptor.addRule()
.post("http://localhost:3000/v1.0/state") .post("http://localhost:3000/v1.0/state/MyStateStore")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.saveStates(stateKeyValueList); Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -296,23 +299,23 @@ public class DaprClientHttpTest {
State<String> stateKeyValue = new State("value", "key", "", null); State<String> stateKeyValue = new State("value", "key", "", null);
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue); List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
mockInterceptor.addRule() mockInterceptor.addRule()
.post("http://localhost:3000/v1.0/state") .post("http://localhost:3000/v1.0/state/MyStateStore")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.saveStates(stateKeyValueList); Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
assertNull(mono.block()); assertNull(mono.block());
} }
@Test @Test
public void simpleSaveStates() { public void simpleSaveStates() {
mockInterceptor.addRule() mockInterceptor.addRule()
.post("http://localhost:3000/v1.0/state") .post("http://localhost:3000/v1.0/state/MyStateStore")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
StateOptions stateOptions = mock(StateOptions.class); StateOptions stateOptions = mock(StateOptions.class);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.saveState("key", "etag", "value", stateOptions); Mono<Void> mono = daprClientHttp.saveState(STATE_STORE_NAME, "key", "etag", "value", stateOptions);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -322,11 +325,11 @@ public class DaprClientHttpTest {
StateOptions stateOptions = mock(StateOptions.class); StateOptions stateOptions = mock(StateOptions.class);
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions); State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
mockInterceptor.addRule() mockInterceptor.addRule()
.delete("http://localhost:3000/v1.0/state/key") .delete("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions); Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -334,11 +337,11 @@ public class DaprClientHttpTest {
public void deleteStateNullEtag() { public void deleteStateNullEtag() {
State<String> stateKeyValue = new State("value", "key", null, null); State<String> stateKeyValue = new State("value", "key", null, null);
mockInterceptor.addRule() mockInterceptor.addRule()
.delete("http://localhost:3000/v1.0/state/key") .delete("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), null); Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -346,11 +349,11 @@ public class DaprClientHttpTest {
public void deleteStateEmptyEtag() { public void deleteStateEmptyEtag() {
State<String> stateKeyValue = new State("value", "key", "", null); State<String> stateKeyValue = new State("value", "key", "", null);
mockInterceptor.addRule() mockInterceptor.addRule()
.delete("http://localhost:3000/v1.0/state/key") .delete("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
Mono<Void> mono = daprClientHttp.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), null); Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
assertNull(mono.block()); assertNull(mono.block());
} }
@ -359,18 +362,27 @@ public class DaprClientHttpTest {
State<String> stateKeyValueNull = new State("value", null, "etag", null); State<String> stateKeyValueNull = new State("value", null, "etag", null);
State<String> stateKeyValueEmpty = new State("value", "", "etag", null); State<String> stateKeyValueEmpty = new State("value", "", "etag", null);
mockInterceptor.addRule() mockInterceptor.addRule()
.delete("http://localhost:3000/v1.0/state/key") .delete("http://localhost:3000/v1.0/state/MyStateStore/key")
.respond(EXPECTED_RESULT); .respond(EXPECTED_RESULT);
daprHttp = new DaprHttp(3000, okHttpClient); daprHttp = new DaprHttp(3000, okHttpClient);
daprClientHttp = new DaprClientHttp(daprHttp); daprClientHttp = new DaprClientHttp(daprHttp);
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState(null, null, null).block(); daprClientHttp.deleteState(STATE_STORE_NAME, null, null, null).block();
}); });
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState("", null, null).block(); daprClientHttp.deleteState(STATE_STORE_NAME, "", null, null).block();
}); });
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState(" ", null, null).block(); daprClientHttp.deleteState(STATE_STORE_NAME, " ", null, null).block();
});
assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState(null, "key", null, null).block();
});
assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState("", "key", null, null).block();
});
assertThrows(IllegalArgumentException.class, () -> {
daprClientHttp.deleteState(" ", "key", null, null).block();
}); });
} }
} }