public string Create(string path, byte[] data, List <ACL> acl, CreateMode mode) { lock (_lock) { if (mode.Sequential) { Interlocked.Increment(ref sequence); int newSequence = sequence; path = path + ZKPathUtil.LeadingZeros(newSequence, 10); } if (Exists(path, false)) { throw new KeeperException.NodeExistsException(); } string parentPath = GetParentPath(path); CheckACL(parentPath, Perms.CREATE); _data.Add(path, new DataAndVersion(data, 0, acl)); _creationTime.Add(path, DateTime.Now.ToUnixTime()); CheckWatch(_nodeWatches, path, EventType.NodeCreated); // we also need to send a child change event for the parent if (!string.IsNullOrEmpty(parentPath)) { CheckWatch(_nodeWatches, parentPath, EventType.NodeChildrenChanged); } return(path); } }
public void TestSequentials() { _connection = EstablishConnection(); string sequentialPath = _connection.Create("/a", new byte[0], CreateMode.EphemeralSequential); int firstSequential = int.Parse(sequentialPath.Substring(2)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == sequentialPath); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == _connection.Create("/a", new byte[0], CreateMode.EphemeralSequential)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == _connection.Create("/a", new byte[0], CreateMode.EphemeralSequential)); Assert.True("/b" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == _connection.Create("/b", new byte[0], CreateMode.EphemeralSequential)); Assert.True("/b" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == _connection.Create("/b", new byte[0], CreateMode.EphemeralSequential)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == _connection.Create("/a", new byte[0], CreateMode.EphemeralSequential)); _connection.Close(); _connection = null; }
public async Task TestSequentials() { _connection = EstablishConnection(); string sequentialPath = await _connection.CreateAsync("/a", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL); int firstSequential = int.Parse(sequentialPath.Substring(2)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == sequentialPath); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == await _connection.CreateAsync("/a", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == await _connection.CreateAsync("/a", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL)); Assert.True("/b" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == await _connection.CreateAsync("/b", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL)); Assert.True("/b" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == await _connection.CreateAsync("/b", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL)); Assert.True("/a" + ZKPathUtil.LeadingZeros(firstSequential++, 10) == await _connection.CreateAsync("/a", new byte[0], CreateMode.EPHEMERAL_SEQUENTIAL)); _connection.Close(); _connection = null; }
public void TestLeadingZeros() { Assert.True("0000000001" == ZKPathUtil.LeadingZeros(1, 10)); }