Skip to content

Commit

Permalink
Merge pull request apache#4 from ewhauser/et-develop
Browse files Browse the repository at this point in the history
Et develop
  • Loading branch information
ewhauser committed Jul 18, 2012
2 parents bf6bee8 + ebc5e38 commit 4b0934b
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 421 deletions.
8 changes: 4 additions & 4 deletions src/dotnet/SolutionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
[assembly: AssemblyDescription("ZooKeeper Client for .NET http://zookeeper.apache.org")]
[assembly: AssemblyProduct("ZooKeeperNet")]
[assembly: AssemblyCopyright("Copyright 2007-2012 ewhauser, omwok. - All rights reserved.")]
[assembly: AssemblyVersion("0.5.3")]
[assembly: AssemblyFileVersion("0.5.3")]

[assembly: AssemblyInformationalVersion("0.5.3.343")]
[assembly: AssemblyVersion("3.3.4.6")]
[assembly: AssemblyFileVersion("3.3.4.6")]

[assembly: AssemblyInformationalVersion("3.3.4.6")]
[assembly: ComVisibleAttribute(false)]
[assembly: CLSCompliantAttribute(false)]

2 changes: 1 addition & 1 deletion src/dotnet/ZooKeeperNet.Recipes/DistributedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public ResetChildWatcher()

public void Process(WatchedEvent @event)
{
LOG.DebugFormat("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.EventType);
LOG.DebugFormat("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.Type);
reset.Set();
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/ZooKeeperNet.Recipes/WriteLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public LockWatcher(WriteLock writeLock)
public void Process(WatchedEvent @event)
{
if (LOG.IsDebugEnabled)
LOG.DebugFormat("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.EventType);
LOG.DebugFormat("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.Type);
try
{
writeLock.Lock();
Expand Down
18 changes: 9 additions & 9 deletions src/dotnet/ZooKeeperNet.Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private class MyWatcher : CountdownWatcher
public override void Process(WatchedEvent @event)
{
base.Process(@event);
if (@event.EventType != EventType.None)
if (@event.Type != EventType.None)
{
try
{
Expand Down Expand Up @@ -212,7 +212,7 @@ public void testMutipleWatcherObjs()
WatchedEvent @event;
watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3d));
Assert.AreEqual(name + i, @event.Path);
Assert.AreEqual(EventType.NodeDataChanged, @event.EventType);
Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);

// small chance that an unexpected message was delivered
Expand Down Expand Up @@ -241,7 +241,7 @@ public void testMutipleWatcherObjs()
WatchedEvent @event;
watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(10d));
Assert.AreEqual(name + i, @event.Path);
Assert.AreEqual(EventType.NodeDataChanged, @event.EventType);
Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);

// small chance that an unexpected message was delivered
Expand Down Expand Up @@ -269,7 +269,7 @@ public void testMutipleWatcherObjs()
WatchedEvent @event;
watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3000));
Assert.AreEqual(name + i, @event.Path);
Assert.AreEqual(EventType.NodeDataChanged, @event.EventType);
Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);

// small chance that an unexpected message was delivered
Expand All @@ -281,7 +281,7 @@ public void testMutipleWatcherObjs()
WatchedEvent event2;
watchers2[i].events.TryTake(out @event2, TimeSpan.FromSeconds(3000));
Assert.AreEqual(name + i, event2.Path);
Assert.AreEqual(EventType.NodeDataChanged, event2.EventType);
Assert.AreEqual(EventType.NodeDataChanged, event2.Type);
Assert.AreEqual(KeeperState.SyncConnected, event2.State);

// small chance that an unexpected message was delivered
Expand Down Expand Up @@ -387,7 +387,7 @@ private void performClientTest(bool withWatcherObj)
WatchedEvent @event;
watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3000));
Assert.AreEqual(frog, @event.Path);
Assert.AreEqual(EventType.NodeCreated, @event.EventType);
Assert.AreEqual(EventType.NodeCreated, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);
// Test child watch and Create with sequence
zk.GetChildren(patPlusBen, true);
Expand Down Expand Up @@ -429,18 +429,18 @@ private void performClientTest(bool withWatcherObj)

watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
Assert.AreEqual(patPlusBen, @event.Path);
Assert.AreEqual(EventType.NodeChildrenChanged, @event.EventType);
Assert.AreEqual(EventType.NodeChildrenChanged, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);
for (int i = 0; i < 10; i++)
{
watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
string name = children.ElementAt(i);
Assert.AreEqual(patPlusBen + "/" + name, @event.Path);
Assert.AreEqual(EventType.NodeDataChanged, @event.EventType);
Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);
watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
Assert.AreEqual(patPlusBen + "/" + name, @event.Path);
Assert.AreEqual(EventType.NodeDeleted, @event.EventType);
Assert.AreEqual(EventType.NodeDeleted, @event.Type);
Assert.AreEqual(KeeperState.SyncConnected, @event.State);
}
zk.Create("/good" + Guid.NewGuid() + "\u0040path", "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
Expand Down
108 changes: 108 additions & 0 deletions src/dotnet/ZooKeeperNet.Tests/RecoveryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading;
using log4net;
using NUnit.Framework;
using Org.Apache.Zookeeper.Data;

namespace ZooKeeperNet.Tests
{
public class RecoveryTest : AbstractZooKeeperTests, IWatcher
{
private readonly ILog LOG = LogManager.GetLogger(typeof(RecoveryTest));
private int setDataCount;
private int processCount;
private readonly string testPath = "/unittests/recoverytests/" + Guid.NewGuid();

[Test, Explicit]
public void ReconnectsWhenDisconnected()
{
using (CancellationTokenSource token = new CancellationTokenSource())
{
Thread thread = new Thread(Run)
{
IsBackground = true,
Name = "RecoveryTest.Run"
};
thread.Start(token.Token);
Thread.Sleep(15*1000);
LOG.Error("STOP ZK!!!! Count: " + processCount);
Thread.Sleep(20*1000);
LOG.Error("START ZK!!! Count: " + processCount);
Thread.Sleep(30*1000);
LOG.Error("Stopping ZK client.");
token.Cancel();
LOG.Error("Waiting for thread to stop..." + processCount);
thread.Join();
if (thread.IsAlive)
Assert.Fail("Thread still alive");
Assert.AreEqual(setDataCount, processCount, "setDataCount == processCount");
LOG.Error("Finished:" + setDataCount + ":" + processCount);
}
}

private void Run(object sender)
{
try
{
CancellationToken token = (CancellationToken)sender;
using (ZooKeeper zooKeeper = CreateClient(this))
{
Stat stat = new Stat();
if (zooKeeper.Exists("/unittests/recoverytests", false) == null)
{
zooKeeper.Create("/unittests", new byte[] {0}, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
zooKeeper.Create("/unittests/recoverytests", new byte[] {0}, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
}
if (zooKeeper.Exists(testPath, false) == null)
{
zooKeeper.Create(testPath, new byte[] {0}, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
}
while (zooKeeper.State.IsAlive() && !token.IsCancellationRequested)
{
try
{
zooKeeper.GetData(testPath, true, stat);
zooKeeper.SetData(testPath, Guid.NewGuid().ToByteArray(), -1);
setDataCount++;
}
catch(KeeperException ke)
{
LOG.Error(ke);
}
}
LOG.Error("Waiting for dispose.");
}
}
catch(Exception ex)
{
LOG.Error(ex);
}
}

public void Process(WatchedEvent @event)
{
LOG.Debug(@event);
if (@event.Type == EventType.NodeCreated || @event.Type == EventType.NodeDataChanged)
{
Interlocked.Increment(ref processCount);
}
}
}
}
Loading

0 comments on commit 4b0934b

Please sign in to comment.