@Test public void testSyncGetStat() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String testName = className + "_" + methodName; System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis())); String path = String.format("/%s/%s", _rootPath, "msg_0"); ZNRecord record = new ZNRecord("msg_0"); ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient); Stat stat = accessor.getStat(path, 0); Assert.assertNull(stat); boolean success = accessor.create(path, record, AccessOption.EPHEMERAL); Assert.assertTrue(success); stat = accessor.getStat(path, 0); Assert.assertNotNull(stat); Assert.assertEquals(stat.getVersion(), 0); Assert.assertNotSame(stat.getEphemeralOwner(), 0); System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis())); }
@Override public Stat getStat(String path, int options) { String clientPath = path; String serverPath = prependChroot(clientPath); Cache<T> cache = getCache(serverPath); if (cache != null) { Stat stat = new Stat(); ZNode znode = cache.get(serverPath); if (znode != null) { return znode.getStat(); } else { // if cache miss, fall back to zk and update cache try { cache.lockWrite(); T data = _baseAccessor.get(serverPath, stat, options); cache.update(serverPath, data, stat); } catch (ZkNoNodeException e) { return null; } finally { cache.unlockWrite(); } return stat; } } // no cache return _baseAccessor.getStat(serverPath, options); }
@Override public Stat getStat(String path, int options) { String clientPath = path; String serverPath = prependChroot(clientPath); Cache<T> cache = getCache(serverPath); if (cache != null) { Stat stat = new Stat(); ZNode znode = cache.get(serverPath); if (znode != null) { return znode.getStat(); } else { // if cache miss, fall back to zk and update cache try { cache.lockWrite(); T data = _baseAccessor.get(serverPath, stat, options); cache.update(serverPath, data, stat); } catch (ZkNoNodeException e) { return null; } finally { cache.unlockWrite(); } return stat; } } // no cache return _baseAccessor.getStat(serverPath, options); }