本文整理汇总了C#中Sharpen.CountDownLatch类的典型用法代码示例。如果您正苦于以下问题:C# CountDownLatch类的具体用法?C# CountDownLatch怎么用?C# CountDownLatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CountDownLatch类属于Sharpen命名空间,在下文中一共展示了CountDownLatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeTrackerTestWithMode
/// <exception cref="System.Exception"></exception>
public virtual void ChangeTrackerTestWithMode(ChangeTracker.ChangeTrackerMode mode
, bool useMockReplicator)
{
CountDownLatch changeTrackerFinishedSignal = new CountDownLatch(1);
CountDownLatch changeReceivedSignal = new CountDownLatch(1);
Uri testURL = GetReplicationURL();
ChangeTrackerClient client = new _ChangeTrackerClient_42(changeTrackerFinishedSignal
, useMockReplicator, changeReceivedSignal);
ChangeTracker changeTracker = new ChangeTracker(testURL, mode, false, 0, client);
changeTracker.SetUsePOST(IsTestingAgainstSyncGateway());
changeTracker.Start();
try
{
bool success = changeReceivedSignal.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(success);
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
changeTracker.Stop();
try
{
bool success = changeTrackerFinishedSignal.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(success);
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
}
示例2: TestChangeTracker
/// <exception cref="System.Exception"></exception>
public virtual void TestChangeTracker()
{
CountDownLatch changeTrackerFinishedSignal = new CountDownLatch(1);
Uri testURL = GetReplicationURL();
ChangeTrackerClient client = new _ChangeTrackerClient_31(changeTrackerFinishedSignal
);
ChangeTracker changeTracker = new ChangeTracker(testURL, ChangeTracker.ChangeTrackerMode
.OneShot, 0, client);
changeTracker.Start();
try
{
bool success = changeTrackerFinishedSignal.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(success);
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:20,代码来源:ChangeTrackerTest.cs
示例3: _BackgroundTask_376
public _BackgroundTask_376(Uri pathToDoc1, string docJson, CountDownLatch httpRequestDoneSignal
)
{
this.pathToDoc1 = pathToDoc1;
this.docJson = docJson;
this.httpRequestDoneSignal = httpRequestDoneSignal;
}
示例4: TestChangeListenerNotificationBatching
public void TestChangeListenerNotificationBatching()
{
const int numDocs = 50;
var atomicInteger = 0;
var doneSignal = new CountDownLatch(1);
database.Changed += (sender, e) => Interlocked.Increment (ref atomicInteger);
database.RunInTransaction(() =>
{
CreateDocuments(database, numDocs);
doneSignal.CountDown();
return true;
});
var success = doneSignal.Await(TimeSpan.FromSeconds(30));
Assert.IsTrue(success);
Assert.AreEqual(1, atomicInteger);
}
示例5: AddDocWithId
/// <exception cref="System.IO.IOException"></exception>
private void AddDocWithId(string docId, string attachmentName)
{
string docJson;
if (attachmentName != null)
{
// add attachment to document
var attachmentStream = (InputStream)GetAsset(attachmentName);
var baos = new MemoryStream();
attachmentStream.Wrapped.CopyTo(baos);
var attachmentBase64 = Convert.ToBase64String(baos.ToArray());
docJson = String.Format("{{\"foo\":1,\"bar\":false, \"_attachments\": {{ \"i_use_couchdb.png\": {{ \"content_type\": \"image/png\", \"data\": \"{0}\" }} }} }}", attachmentBase64);
}
else
{
docJson = @"{""foo"":1,""bar"":false}";
}
// push a document to server
var replicationUrlTrailingDoc1 = new Uri(string.Format("{0}/{1}", GetReplicationURL(), docId));
var pathToDoc1 = new Uri(replicationUrlTrailingDoc1, docId);
Log.D(Tag, "Send http request to " + pathToDoc1);
CountDownLatch httpRequestDoneSignal = new CountDownLatch(1);
Task.Factory.StartNew(() =>
{
var httpclient = new HttpClient(); //CouchbaseLiteHttpClientFactory.Instance.GetHttpClient();
HttpResponseMessage response;
try
{
var request = new HttpRequestMessage();
request.Headers.Add("Accept", "*/*");
var postTask = httpclient.PutAsync(pathToDoc1.AbsoluteUri, new StringContent(docJson, Encoding.UTF8, "application/json"));
response = postTask.Result;
var statusLine = response.StatusCode;
Log.D(ReplicationTest.Tag, "Got response: " + statusLine);
Assert.IsTrue(statusLine == HttpStatusCode.Created);
}
catch (ProtocolViolationException e)
{
Assert.IsNull(e, "Got ClientProtocolException: " + e.Message);
}
catch (IOException e)
{
Assert.IsNull(e, "Got IOException: " + e.Message);
}
httpRequestDoneSignal.CountDown();
});
Log.D(Tag, "Waiting for http request to finish");
try
{
Assert.IsTrue(httpRequestDoneSignal.Await(TimeSpan.FromSeconds(10)));
Log.D(Tag, "http request finished");
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
WorkaroundSyncGatewayRaceCondition();
}
示例6: TestPushReplicationCanMissDocs
public void TestPushReplicationCanMissDocs()
{
Assert.AreEqual(0, database.LastSequenceNumber);
var properties1 = new Dictionary<string, object>();
properties1["doc1"] = "testPushReplicationCanMissDocs";
var doc1 = CreateDocumentWithProperties(database, properties1);
var properties2 = new Dictionary<string, object>();
properties2["doc2"] = "testPushReplicationCanMissDocs";
var doc2 = CreateDocumentWithProperties(database, properties2);
var doc2UnsavedRev = doc2.CreateRevision();
var attachmentStream = GetAsset("attachment.png");
doc2UnsavedRev.SetAttachment("attachment.png", "image/png", attachmentStream);
var doc2Rev = doc2UnsavedRev.Save();
Assert.IsNotNull(doc2Rev);
var httpClientFactory = new MockHttpClientFactory();
manager.DefaultHttpClientFactory = httpClientFactory;
var httpHandler = httpClientFactory.HttpHandler;
httpHandler.AddResponderFakeLocalDocumentUpdate404();
var json = "{\"error\":\"not_found\",\"reason\":\"missing\"}";
MockHttpRequestHandler.HttpResponseDelegate bulkDocsResponder = (request) =>
{
return MockHttpRequestHandler.GenerateHttpResponseMessage(HttpStatusCode.NotFound, null, json);
};
httpHandler.SetResponder("_bulk_docs", bulkDocsResponder);
MockHttpRequestHandler.HttpResponseDelegate doc2Responder = (request) =>
{
var responseObject = new Dictionary<string, object>();
responseObject["id"] = doc2.Id;
responseObject["ok"] = true;
responseObject["rev"] = doc2.CurrentRevisionId;
return MockHttpRequestHandler.GenerateHttpResponseMessage(responseObject);
};
httpHandler.SetResponder(doc2.Id, bulkDocsResponder);
var replicationDoneSignal = new CountDownLatch(1);
var observer = new ReplicationObserver(replicationDoneSignal);
var pusher = database.CreatePushReplication(GetReplicationURL());
pusher.Changed += observer.Changed;
pusher.Start();
var success = replicationDoneSignal.Await(TimeSpan.FromSeconds(5));
Assert.IsTrue(success);
Assert.IsNotNull(pusher.LastError);
System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(500));
var localLastSequence = database.LastSequenceWithCheckpointId(pusher.RemoteCheckpointDocID());
Log.D(Tag, "dtabase.lastSequenceWithCheckpointId(): " + localLastSequence);
Log.D(Tag, "doc2.getCUrrentRevision().getSequence(): " + doc2.CurrentRevision.Sequence);
// Since doc1 failed, the database should _not_ have had its lastSequence bumped to doc2's sequence number.
// If it did, it's bug: github.com/couchbase/couchbase-lite-java-core/issues/95
Assert.IsFalse(doc2.CurrentRevision.Sequence.ToString().Equals(localLastSequence));
Assert.IsNull(localLastSequence);
Assert.IsTrue(doc2.CurrentRevision.Sequence > 0);
}
示例7: ChangeTrackerTestClient
public ChangeTrackerTestClient(CountDownLatch stoppedSignal, CountDownLatch changedSignal)
{
this.stoppedSignal = stoppedSignal;
this.changedSignal = changedSignal;
HttpClientFactory = new MockHttpClientFactory();
}
示例8: TestChangeTrackerBackoff
private void TestChangeTrackerBackoff(MockHttpClientFactory httpClientFactory)
{
var changeTrackerFinishedSignal = new CountDownLatch(1);
var client = new ChangeTrackerTestClient(changeTrackerFinishedSignal, null);
client.HttpClientFactory = httpClientFactory;
var testUrl = GetReplicationURL();
var scheduler = new SingleTaskThreadpoolScheduler();
var changeTracker = new ChangeTracker(testUrl, ChangeTrackerMode.LongPoll, 0, false, client, new TaskFactory(scheduler));
changeTracker.UsePost = IsSyncGateway(testUrl);
changeTracker.Start();
// sleep for a few seconds
Thread.Sleep(15 * 1000);
// make sure we got less than 10 requests in those 10 seconds (if it was hammering, we'd get a lot more)
var handler = client.HttpRequestHandler;
Assert.IsTrue(handler.CapturedRequests.Count < 25);
Assert.IsTrue(changeTracker.backoff.NumAttempts > 0, "Observed attempts: {0}".Fmt(changeTracker.backoff.NumAttempts));
handler.ClearResponders();
handler.AddResponderReturnEmptyChangesFeed();
// at this point, the change tracker backoff should cause it to sleep for about 3 seconds
// and so lets wait 3 seconds until it wakes up and starts getting valid responses
Thread.Sleep(3 * 1000);
// now find the delta in requests received in a 2s period
int before = handler.CapturedRequests.Count;
Thread.Sleep(2 * 1000);
int after = handler.CapturedRequests.Count;
// assert that the delta is high, because at this point the change tracker should
// be hammering away
Assert.IsTrue((after - before) > 25);
// the backoff numAttempts should have been reset to 0
Assert.IsTrue(changeTracker.backoff.NumAttempts == 0);
changeTracker.Stop();
var success = changeTrackerFinishedSignal.Await(TimeSpan.FromSeconds(30));
Assert.IsTrue(success);
}
示例9: TestPusher
/// <exception cref="System.Exception"></exception>
public virtual void TestPusher()
{
CountDownLatch replicationDoneSignal = new CountDownLatch(1);
Uri remote = GetReplicationURL();
string docIdTimestamp = System.Convert.ToString(Runtime.CurrentTimeMillis());
// Create some documents:
IDictionary<string, object> documentProperties = new Dictionary<string, object>();
string doc1Id = string.Format("doc1-%s", docIdTimestamp);
documentProperties.Put("_id", doc1Id);
documentProperties.Put("foo", 1);
documentProperties.Put("bar", false);
Body body = new Body(documentProperties);
RevisionInternal rev1 = new RevisionInternal(body, database);
Status status = new Status();
rev1 = database.PutRevision(rev1, null, false, status);
NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
documentProperties.Put("_rev", rev1.GetRevId());
documentProperties.Put("UPDATED", true);
RevisionInternal rev2 = database.PutRevision(new RevisionInternal(documentProperties
, database), rev1.GetRevId(), false, status);
NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
documentProperties = new Dictionary<string, object>();
string doc2Id = string.Format("doc2-%s", docIdTimestamp);
documentProperties.Put("_id", doc2Id);
documentProperties.Put("baz", 666);
documentProperties.Put("fnord", true);
database.PutRevision(new RevisionInternal(documentProperties, database), null, false
, status);
NUnit.Framework.Assert.AreEqual(Status.Created, status.GetCode());
bool continuous = false;
Replication repl = database.CreatePushReplication(remote);
repl.SetContinuous(continuous);
repl.SetCreateTarget(true);
// Check the replication's properties:
NUnit.Framework.Assert.AreEqual(database, repl.GetLocalDatabase());
NUnit.Framework.Assert.AreEqual(remote, repl.GetRemoteUrl());
NUnit.Framework.Assert.IsFalse(repl.IsPull());
NUnit.Framework.Assert.IsFalse(repl.IsContinuous());
NUnit.Framework.Assert.IsTrue(repl.ShouldCreateTarget());
NUnit.Framework.Assert.IsNull(repl.GetFilter());
NUnit.Framework.Assert.IsNull(repl.GetFilterParams());
// TODO: CAssertNil(r1.doc_ids);
// TODO: CAssertNil(r1.headers);
// Check that the replication hasn't started running:
NUnit.Framework.Assert.IsFalse(repl.IsRunning());
NUnit.Framework.Assert.AreEqual(Replication.ReplicationStatus.ReplicationStopped,
repl.GetStatus());
NUnit.Framework.Assert.AreEqual(0, repl.GetCompletedChangesCount());
NUnit.Framework.Assert.AreEqual(0, repl.GetChangesCount());
NUnit.Framework.Assert.IsNull(repl.GetLastError());
RunReplication(repl);
// make sure doc1 is there
// TODO: make sure doc2 is there (refactoring needed)
Uri replicationUrlTrailing = new Uri(string.Format("%s/", remote.ToExternalForm()
));
Uri pathToDoc = new Uri(replicationUrlTrailing, doc1Id);
Log.D(Tag, "Send http request to " + pathToDoc);
CountDownLatch httpRequestDoneSignal = new CountDownLatch(1);
BackgroundTask getDocTask = new _BackgroundTask_122(pathToDoc, doc1Id, httpRequestDoneSignal
);
//Closes the connection.
getDocTask.Execute();
Log.D(Tag, "Waiting for http request to finish");
try
{
httpRequestDoneSignal.Await(300, TimeUnit.Seconds);
Log.D(Tag, "http request finished");
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
Log.D(Tag, "testPusher() finished");
}
示例10: ReplicationObserver
internal ReplicationObserver(ReplicationTest _enclosing, CountDownLatch doneSignal
)
{
this._enclosing = _enclosing;
this.doneSignal = doneSignal;
}
示例11: TestGoOffline
/// <exception cref="System.Exception"></exception>
public virtual void TestGoOffline()
{
Uri remote = GetReplicationURL();
CountDownLatch replicationDoneSignal = new CountDownLatch(1);
Replication repl = database.CreatePullReplication(remote);
repl.SetContinuous(true);
repl.Start();
repl.GoOffline();
NUnit.Framework.Assert.IsTrue(repl.GetStatus() == Replication.ReplicationStatus.ReplicationOffline
);
}
示例12: TestFetchRemoteCheckpointDoc
/// <exception cref="System.Exception"></exception>
public virtual void TestFetchRemoteCheckpointDoc()
{
HttpClientFactory mockHttpClientFactory = new _HttpClientFactory_583();
Log.D("TEST", "testFetchRemoteCheckpointDoc() called");
string dbUrlString = "http://fake.test-url.com:4984/fake/";
Uri remote = new Uri(dbUrlString);
database.SetLastSequence("1", remote, true);
// otherwise fetchRemoteCheckpoint won't contact remote
Replication replicator = new Pusher(database, remote, false, mockHttpClientFactory
, manager.GetWorkExecutor());
CountDownLatch doneSignal = new CountDownLatch(1);
ReplicationTest.ReplicationObserver replicationObserver = new ReplicationTest.ReplicationObserver
(this, doneSignal);
replicator.AddChangeListener(replicationObserver);
replicator.FetchRemoteCheckpointDoc();
Log.D(Tag, "testFetchRemoteCheckpointDoc() Waiting for replicator to finish");
try
{
bool succeeded = doneSignal.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(succeeded);
Log.D(Tag, "testFetchRemoteCheckpointDoc() replicator finished");
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
string errorMessage = "Since we are passing in a mock http client that always throws "
+ "errors, we expect the replicator to be in an error state";
NUnit.Framework.Assert.IsNotNull(errorMessage, replicator.GetLastError());
}
示例13: _Runnable_482
public _Runnable_482(Replication replication, CountDownLatch doneSignal)
{
this.replication = replication;
this.doneSignal = doneSignal;
}
示例14: ReplicationWatcherThread
private CountDownLatch ReplicationWatcherThread(Replication replication)
{
CountDownLatch doneSignal = new CountDownLatch(1);
new Sharpen.Thread(new _Runnable_482(replication, doneSignal)).Start();
return doneSignal;
}
示例15: RunReplication
private void RunReplication(Replication replication)
{
CountDownLatch replicationDoneSignal = new CountDownLatch(1);
ReplicationTest.ReplicationObserver replicationObserver = new ReplicationTest.ReplicationObserver
(this, replicationDoneSignal);
replication.AddChangeListener(replicationObserver);
replication.Start();
CountDownLatch replicationDoneSignalPolling = ReplicationWatcherThread(replication
);
Log.D(Tag, "Waiting for replicator to finish");
try
{
bool success = replicationDoneSignal.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(success);
success = replicationDoneSignalPolling.Await(300, TimeUnit.Seconds);
NUnit.Framework.Assert.IsTrue(success);
Log.D(Tag, "replicator finished");
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e);
}
}