Last active
March 8, 2017 19:53
-
-
Save jolovin-mmi/905e08b7eb5fd52f83f60562bedd9ca9 to your computer and use it in GitHub Desktop.
Custom Cluster Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ClusterTest | |
{ | |
public class Program | |
{ | |
private const string ReadFromDb = "http://genesis:9001"; | |
private const string WriteToDb = "http://uatwebserver.mountville.dmz:9000"; | |
public static void Main(string[] args) | |
{ | |
var docStore = new DocumentStore | |
{ | |
Url = ReadFromDb, | |
DefaultDatabase = "MMI" | |
}; | |
docStore.Conventions.ReplicationInformerFactory = (url, jsonRequestFactory, requestTimeMetricGetter) => new CustomReplicationInformer(docStore.Conventions, jsonRequestFactory, requestTimeMetricGetter); | |
docStore.Initialize(); | |
var testDoc = new TestDoc { Note = "Hello, World!" }; | |
using (var session = docStore.OpenSession()) | |
{ | |
session.Store(testDoc); | |
session.SaveChanges(); //null reference here | |
} | |
docStore.Dispose(); | |
} | |
public class CustomReplicationInformer : ReplicationInformerBase<ServerClient>, IDocumentStoreReplicationInformer | |
{ | |
public CustomReplicationInformer(DocumentConvention conventions, HttpJsonRequestFactory jsonRequestFactory, Func<string, IRequestTimeMetric> requestTimeMetricGetter) : base(conventions, jsonRequestFactory, requestTimeMetricGetter) | |
{ | |
} | |
public ReplicationDestination[] FailoverServers { get; set; } | |
public void Dispose() | |
{ | |
base.Dispose(); | |
} | |
public int GetReadStripingBase(bool increment) | |
{ | |
return base.GetReadStripingBase(increment); | |
} | |
public Task<T> ExecuteWithReplicationAsync<T>(HttpMethod method, string primaryUrl, OperationCredentials primaryCredentials, | |
int currentRequest, int currentReadStripingBase, Func<OperationMetadata, IRequestTimeMetric, Task<T>> operation, CancellationToken token = new CancellationToken()) | |
{ | |
primaryUrl = method.Method == "GET" ? ReadFromDb : WriteToDb; //This is the only thing I care about | |
return base.ExecuteWithReplicationAsync(method, primaryUrl, primaryCredentials, currentRequest, currentReadStripingBase, operation, token); | |
} | |
public int DelayTimeInMiliSec { get; set; } | |
public List<OperationMetadata> ReplicationDestinations { get; } | |
public List<OperationMetadata> ReplicationDestinationsUrls { get; } | |
public FailureCounters FailureCounters { get; } | |
public event EventHandler<FailoverStatusChangedEventArgs> FailoverStatusChanged; | |
public Task UpdateReplicationInformationIfNeededAsync(AsyncServerClient serverClient) | |
{ | |
return null; | |
} | |
public override void RefreshReplicationInformation(ServerClient client) | |
{ | |
//would rather just use the base implementation but can't | |
throw new NotImplementedException(); | |
} | |
protected override void UpdateReplicationInformationFromDocument(JsonDocument document) | |
{ | |
//would rather just use the base implementation but can't | |
throw new NotImplementedException(); | |
} | |
protected override string GetServerCheckUrl(string baseUrl) | |
{ | |
//would rather just use the base implementation but can't | |
throw new NotImplementedException(); | |
} | |
public override void ClearReplicationInformationLocalCache(ServerClient client) | |
{ | |
//would rather just use the base implementation but can't | |
throw new NotImplementedException(); | |
} | |
} | |
public class TestDoc | |
{ | |
public string Id { get; set; } | |
public string Note { get; set; } | |
public DateTime TimeStamp { get; set; } | |
public TestDoc() | |
{ | |
Id = "TestDocs/"; | |
TimeStamp = DateTime.Now; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment