public static PersistentState createEphemeral() { return new PersistentState(); }
private void load(Path stateFile) { state = new PersistentState(stateFile); stateStr = state; readState(stateStr); }
/** Put state file name into DataState then only have here */ private DataState readDataState(Path p) { Path versionFile = p.resolve(FN.STATE); if ( ! Files.exists(versionFile) ) throw new DeltaConfigException("No state file: "+versionFile); PersistentState state = new PersistentState(versionFile); if ( state.getString().isEmpty() ) throw new DeltaConfigException("Error reading state: version file exist but is empty"); DataState dataState = new DataState(this, state) ; return dataState; }
/** Create new, initialize state. */ /*package*/ DataState(Zone zone, Path stateFile, LocalStorageType storage, Id dsRef, String name, String uri, Version version, Id patchId) { this.zone = zone; this.datasource = dsRef; if ( stateFile != null ) this.state = new PersistentState(stateFile); else this.state = PersistentState.createEphemeral(); this.stateStr = state; this.version = version; this.patchId = patchId; this.name = name; this.uri = uri; this.storage = storage; writeState(this); }
@Test public void pState_String_03() { PersistentState ps = new PersistentState(filename); String data = "test data\n\t"; ps.setString(data); assertEquals(data, ps.getString()); PersistentState ps2 = new PersistentState(filename); assertEquals(data, ps2.getString()); }
@Test public void pCounter_02() { PersistentState pc = new PersistentState(filename) ; pc.inc() ; assertEquals(1, pc.getInteger()); PersistentState pc2 = new PersistentState(filename) ; assertEquals(1, pc2.getInteger()); }
@Test public void pState_01() { PersistentState ps = new PersistentState(filename); assertEquals(0, ps.get().length); }
@Test public void pCounter_01() { PersistentState pc = new PersistentState(filename) ; assertEquals(0, pc.getInteger()); }
@Test public void pState_02() { PersistentState ps = new PersistentState(filename); byte[] b = new byte[4]; Bytes.setInt(-99, b); ps.set(b); assertEquals(4, ps.get().length); PersistentState ps2 = new PersistentState(filename); assertEquals(4, ps2.get().length); }
@Test public void pCounter_03() { PersistentState pc = new PersistentState(filename) ; pc.setInteger(10) ; assertEquals(10, pc.getInteger()); long x = pc.inc() ; assertEquals(11, pc.getInteger()); PersistentState pc2 = new PersistentState(filename) ; assertEquals(11, pc2.getInteger()); }