Change StateMachinePersist interface

- Remove away from plain serialize/deserialize to write/read
  concept which works better in a generic abstraction.
- Tweak related class in zookeeper package.
- Relates to #35
This commit is contained in:
Janne Valkealahti
2015-06-20 15:41:35 +01:00
parent e2fe4907d3
commit 44d09f257e
4 changed files with 88 additions and 28 deletions

View File

@@ -18,20 +18,37 @@ package org.springframework.statemachine.zookeeper;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.ensemble.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
public class KryoStateMachinePersistTests {
public class ZookeeperStateMachinePersistTests extends AbstractZookeeperTests {
@Override
protected AnnotationConfigApplicationContext buildContext() {
return new AnnotationConfigApplicationContext();
}
@Test
public void testStateEvent() {
StateMachinePersist<String, String> persist = new KryoStateMachinePersist<String, String>();
public void testStateEvent() throws Exception {
context.register(ZkServerConfig.class, BaseConfig.class);
context.refresh();
CuratorFramework curatorClient =
context.getBean("curatorClient", CuratorFramework.class);
curatorClient.create().forPath("/KryoStateMachinePersistTests");
StateMachinePersist<String, String, Stat> persist = new ZookeeperStateMachinePersist<String, String>(
curatorClient, "/KryoStateMachinePersistTests");
StateMachineContext<String, String> contextOut =
new DefaultStateMachineContext<String, String>(null, "S1", "E1", null, null);
byte[] data = persist.serialize(contextOut);
StateMachineContext<String, String> contextIn = persist.deserialize(data);
persist.write(contextOut, new Stat());
StateMachineContext<String, String> contextIn = persist.read(new Stat());
assertThat(contextOut.getState(), is(contextIn.getState()));
assertThat(contextOut.getEvent(), is(contextIn.getEvent()));