def test_persistence(self):
        tempDir = tempfile.mkdtemp()

        try:
            testValues = {}
            def testWrite(passIx):
                try:
                    testKeyspaces = [
                        SharedState.Keyspace("TakeHighestIdKeyType",
                                             NativeJson.Json("TestSpace%s" % ix), 3) \
                        for ix in range(3)
                        ]

                    harness = self.getHarness(inMemory=True, cachePathOverride=tempDir)
                    v1 = harness.newView()
                    for space in testKeyspaces:
                        rng = SharedState.KeyRange(space, 0, None, None, True, False)
                        v1.subscribe(rng)

                    for ix in range(9):
                        keyspaceIx = (ix+passIx) % len(testKeyspaces)

                        space = testKeyspaces[keyspaceIx] #random.choice(testKeyspaces)
                        with SharedState.Transaction(v1):
                            key = SharedState.Key(space,
                                                  (NativeJson.Json("key %s" % ix), NativeJson.Json(''), NativeJson.Json('')))
                            value = JsonNative.Json(
                                '<value is %s in space %s on pass %s: %s>' %
                                    (ix, keyspaceIx, passIx, uuid.uuid4().hex)
                                )
                            v1[key] = value
                            testValues[key] = value

                    v1.flush()

                    time.sleep(0.01)
                    harness.teardown()
                    harness = self.getHarness(inMemory=True, cachePathOverride=tempDir)

                    v1 = harness.newView()
                    for space in testKeyspaces:
                        rng = SharedState.KeyRange(space, 0, None, None, True, False)
                        v1.subscribe(rng)

                    for key, value in testValues.iteritems():
                        self.assertSharedStateKeyResolvesToValue(key, v1, testValues[key])
                except:
                    logging.warn("Exception: %s", traceback.format_exc())
                    raise
                finally:
                    time.sleep(0.01)
                    harness.teardown()

            for ix in range(2):
                testWrite(ix)
        finally:
            shutil.rmtree(tempDir)
dataset/ETHPy150Open ufora/ufora/ufora/distributed/SharedState/SharedState_test.py/TestSharedState.test_persistence/original