本文整理汇总了C#中ShardMapManager.GetListShardMap方法的典型用法代码示例。如果您正苦于以下问题:C# ShardMapManager.GetListShardMap方法的具体用法?C# ShardMapManager.GetListShardMap怎么用?C# ShardMapManager.GetListShardMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShardMapManager
的用法示例。
在下文中一共展示了ShardMapManager.GetListShardMap方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePointMappingIdempotency
public void UpdatePointMappingIdempotency()
{
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
Shard s1 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]));
Assert.IsNotNull(s1);
Shard s2 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]));
Assert.IsNotNull(s2);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s1);
// Online -> Offline - No Location Change
PointMappingUpdate pu = new PointMappingUpdate
{
Status = MappingStatus.Offline
};
PointMapping<int> presult = lsm.UpdateMapping(p1, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Offline);
// Offline -> Offline - No Location Change
pu = new PointMappingUpdate
{
Status = MappingStatus.Offline
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Offline);
// Offline -> Offline - Location Change
pu = new PointMappingUpdate
{
Shard = s2
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Offline);
Assert.AreEqual(s2.Location, presult.Shard.Location);
// Offline -> Online - No Location Change
pu = new PointMappingUpdate
{
Status = MappingStatus.Online
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Online);
// Online -> Offline - Location Change
pu = new PointMappingUpdate
{
Status = MappingStatus.Offline,
Shard = s1
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Offline);
Assert.AreEqual(s1.Location, presult.Shard.Location);
// Offline -> Online - Location Change
pu = new PointMappingUpdate
{
Status = MappingStatus.Online,
Shard = s2
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Online);
Assert.AreEqual(s2.Location, presult.Shard.Location);
// Online -> Online - No Location Change
pu = new PointMappingUpdate
{
Status = MappingStatus.Online
};
presult = lsm.UpdateMapping(presult, pu);
Assert.IsNotNull(presult);
Assert.IsTrue(presult.Status == MappingStatus.Online);
// Online -> Online - Location Change
pu = new PointMappingUpdate
{
//.........这里部分代码省略.........
示例2: AddPointMappingFailGSMAfterSuccessLSMSingleRetry
public void AddPointMappingFailGSMAfterSuccessLSMSingleRetry()
{
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StubStoreOperationFactory()
{
CallBase = true,
CreateAddMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMapping =
(_smm, _opcode, _ssm, _sm) => new NTimeFailingAddMappingOperation(1, _smm, _opcode, _ssm, _sm)
},
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapFaultHandlingTests.s_listShardMapName);
Assert.IsNotNull(lsm);
Shard s = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapFaultHandlingTests.s_shardedDBs[0]));
Assert.IsNotNull(s);
bool failed = false;
try
{
PointMapping<int> p1 = lsm.CreatePointMapping(2, s);
}
catch (ShardManagementException)
{
failed = true;
}
Assert.IsFalse(failed);
}
示例3: KillConnectionOnOfflinePointMapping
public void KillConnectionOnOfflinePointMapping()
{
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero),
RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s);
using (SqlConnection conn = lsm.OpenConnectionForKeyAsync(1, Globals.ShardUserConnectionString).Result)
{
Assert.AreEqual(ConnectionState.Open, conn.State);
PointMappingUpdate pu = new PointMappingUpdate();
pu.Status = MappingStatus.Offline;
PointMapping<int> pNew = lsm.UpdateMapping(p1, pu);
Assert.IsNotNull(pNew);
bool failed = false;
try
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select 1";
cmd.CommandType = CommandType.Text;
using (SqlDataReader rdr = cmd.ExecuteReader())
{
}
}
}
catch (SqlException)
{
failed = true;
}
Assert.AreEqual(true, failed);
Assert.AreEqual(ConnectionState.Closed, conn.State);
failed = false;
// Open 2nd connection.
try
{
using (SqlConnection conn2 = lsm.OpenConnectionForKeyAsync(1, Globals.ShardUserConnectionString).Result)
{
}
}
catch (AggregateException ex)
{
var sme = ex.InnerException as ShardManagementException;
if (sme != null)
{
failed = true;
Assert.AreEqual(ShardManagementErrorCode.MappingIsOffline, sme.ErrorCode);
}
}
Assert.AreEqual(true, failed);
// Mark the mapping online again so that it will be cleaned up
pu.Status = MappingStatus.Online;
PointMapping<int> pUpdated = lsm.UpdateMapping(pNew, pu);
Assert.IsNotNull(pUpdated);
failed = false;
// Open 3rd connection. This should succeed.
try
{
using (SqlConnection conn3 = lsm.OpenConnectionForKey(1, Globals.ShardUserConnectionString))
{
}
}
catch (ShardManagementException)
{
failed = true;
}
Assert.AreEqual(false, failed);
}
}
示例4: UpdatePointMappingLocation
public void UpdatePointMappingLocation()
{
CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
countingCache,
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
Shard s1 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]));
Assert.IsNotNull(s1);
Shard s2 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]));
Assert.IsNotNull(s2);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s1);
PointMappingUpdate pu = new PointMappingUpdate();
pu.Status = MappingStatus.Offline; // Shard location in a mapping cannot be changed unless it is offline.
PointMapping<int> pOffline = lsm.UpdateMapping(p1, pu);
Assert.IsNotNull(pOffline);
Assert.AreEqual(pu.Status, pOffline.Status);
pu.Shard = s2;
PointMapping<int> pNew = lsm.UpdateMapping(pOffline, pu);
Assert.IsNotNull(pNew);
PointMapping<int> p2 = lsm.GetMappingForKey(1);
Assert.IsNotNull(p2);
Assert.AreEqual(0, countingCache.LookupMappingHitCount);
Assert.AreEqual(s2.Id, p2.Shard.Id);
}
示例5: DeletePointMappingDefault
public void DeletePointMappingDefault()
{
CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
countingCache,
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero),
RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s);
PointMapping<int> p2 = lsm.GetMappingForKey(1);
Assert.IsNotNull(p2);
Assert.AreEqual(0, countingCache.LookupMappingHitCount);
// The mapping must be made offline first before it can be deleted.
PointMappingUpdate ru = new PointMappingUpdate();
ru.Status = MappingStatus.Offline;
PointMapping<int> mappingToDelete = lsm.UpdateMapping(p1, ru);
lsm.DeleteMapping(mappingToDelete);
// Verify that the mapping is removed from cache.
bool lookupFailed = false;
try
{
PointMapping<int> pLookup = lsm.GetMappingForKey(1);
}
catch (ShardManagementException sme)
{
Assert.AreEqual(ShardManagementErrorCategory.ListShardMap, sme.ErrorCategory);
Assert.AreEqual(ShardManagementErrorCode.MappingNotFoundForKey, sme.ErrorCode);
lookupFailed = true;
}
Assert.IsTrue(lookupFailed);
Assert.AreEqual(0, countingCache.LookupMappingMissCount);
}
示例6: UpdatePointMappingDefault
public void UpdatePointMappingDefault()
{
CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
countingCache,
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero),
RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s);
PointMappingUpdate pu = new PointMappingUpdate();
pu.Status = MappingStatus.Offline;
PointMapping<int> pNew = lsm.UpdateMapping(p1, pu);
Assert.IsNotNull(pNew);
PointMapping<int> p2 = lsm.GetMappingForKey(1);
Assert.IsNotNull(p2);
Assert.AreEqual(0, countingCache.LookupMappingHitCount);
// Mark the mapping online again so that it will be cleaned up
pu.Status = MappingStatus.Online;
PointMapping<int> pUpdated = lsm.UpdateMapping(pNew, pu);
Assert.IsNotNull(pUpdated);
}
示例7: AddPointMappingDuplicate
public void AddPointMappingDuplicate()
{
CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
countingCache,
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s);
Assert.IsNotNull(p1);
bool addFailed = false;
try
{
// add same point mapping again.
PointMapping<int> pNew = lsm.CreatePointMapping(1, s);
}
catch (ShardManagementException sme)
{
Assert.AreEqual(ShardManagementErrorCategory.ListShardMap, sme.ErrorCategory);
Assert.AreEqual(ShardManagementErrorCode.MappingPointAlreadyMapped, sme.ErrorCode);
addFailed = true;
}
Assert.IsTrue(addFailed);
PointMapping<int> p2 = lsm.GetMappingForKey(1);
Assert.IsNotNull(p2);
Assert.AreEqual(0, countingCache.LookupMappingHitCount);
}
示例8: AddPointMappingAbortGSMDoAndGSMUndo
public void AddPointMappingAbortGSMDoAndGSMUndo()
{
bool shouldThrow = true;
IStoreOperationFactory sof = new StubStoreOperationFactory()
{
CallBase = true,
CreateAddMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMapping =
(_smm, _opcode, _ssm, _sm) =>
{
StubAddMappingOperation op = new StubAddMappingOperation(_smm, _opcode, _ssm, _sm);
op.CallBase = true;
op.DoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
{
if (shouldThrow)
{
throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
}
else
{
// Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
var original = op.DoGlobalPostLocalExecuteIStoreTransactionScope;
op.DoGlobalPostLocalExecuteIStoreTransactionScope = null;
try
{
return op.DoGlobalPostLocalExecute(ts);
}
finally
{
op.DoGlobalPostLocalExecuteIStoreTransactionScope = original;
}
}
};
op.UndoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
{
if (shouldThrow)
{
throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
}
else
{
// Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
var original = op.UndoGlobalPostLocalExecuteIStoreTransactionScope;
op.UndoGlobalPostLocalExecuteIStoreTransactionScope = null;
try
{
return op.UndoGlobalPostLocalExecute(ts);
}
finally
{
op.UndoGlobalPostLocalExecuteIStoreTransactionScope = original;
}
}
};
return op;
}
};
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
sof,
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
ShardLocation sl2 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
Shard s2 = lsm.CreateShard(sl2);
Assert.IsNotNull(s2);
bool storeOperationFailed = false;
try
{
PointMapping<int> p1 = lsm.CreatePointMapping(2, s);
Assert.IsNotNull(p1);
}
catch (ShardManagementException sme)
{
Assert.AreEqual(ShardManagementErrorCategory.ListShardMap, sme.ErrorCategory);
Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
storeOperationFailed = true;
}
Assert.IsTrue(storeOperationFailed);
// Obtain the pending operations.
var pendingOperations = ShardMapperTests.GetPendingStoreOperations();
Assert.AreEqual(pendingOperations.Count(), 1);
//.........这里部分代码省略.........
示例9: UpdatePointMappingLocationAbortLSM
public void UpdatePointMappingLocationAbortLSM()
{
bool shouldThrow = false;
IStoreOperationFactory sof = new StubStoreOperationFactory()
{
CallBase = true,
CreateUpdateMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingIStoreMappingStringGuid =
(_smm, _opcode, _ssm, _sms, _smt, _p, _loid) =>
{
StubUpdateMappingOperation op = new StubUpdateMappingOperation(_smm, _opcode, _ssm, _sms, _smt, _p, _loid);
op.CallBase = true;
if (shouldThrow)
{
// Abort on target.
op.DoLocalTargetExecuteIStoreTransactionScope = (ts) =>
{
throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
};
}
return op;
}
};
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
sof,
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
Shard s1 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]));
Assert.IsNotNull(s1);
Shard s2 = lsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]));
Assert.IsNotNull(s2);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s1);
PointMappingUpdate pu1 = new PointMappingUpdate();
// Take the mapping offline first before the shard location can be updated.
pu1.Status = MappingStatus.Offline;
PointMapping<int> pNew = lsm.UpdateMapping(p1, pu1);
PointMappingUpdate pu2 = new PointMappingUpdate();
pu2.Shard = s2;
shouldThrow = true;
bool storeOperationFailed = false;
try
{
pNew = lsm.UpdateMapping(pNew, pu2);
Assert.IsNotNull(pNew);
}
catch (ShardManagementException sme)
{
Assert.AreEqual(ShardManagementErrorCategory.ListShardMap, sme.ErrorCategory);
Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
storeOperationFailed = true;
}
Assert.IsTrue(storeOperationFailed);
// validation: validate location of the mapping.
PointMapping<int> pValidate = lsm.GetMappingForKey(1);
Assert.AreEqual(p1.Shard.Id, pValidate.Shard.Id);
}
示例10: DeletePointMappingAbortLSM
public void DeletePointMappingAbortLSM()
{
IStoreOperationFactory sof = new StubStoreOperationFactory()
{
CallBase = true,
CreateRemoveMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingGuid =
(_smm, _opcode, _ssm, _sm, _loid) =>
{
StubRemoveMappingOperation op = new StubRemoveMappingOperation(_smm, _opcode, _ssm, _sm, _loid);
op.CallBase = true;
op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
{
throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
};
return op;
}
};
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
sof,
new CacheStore(),
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(1, s);
PointMappingUpdate ru = new PointMappingUpdate();
ru.Status = MappingStatus.Offline;
// The mapping must be made offline before it can be deleted.
p1 = lsm.UpdateMapping(p1, ru);
Assert.AreEqual(MappingStatus.Offline, p1.Status);
bool storeOperationFailed = false;
try
{
lsm.DeleteMapping(p1);
}
catch (ShardManagementException sme)
{
Assert.AreEqual(ShardManagementErrorCategory.ListShardMap, sme.ErrorCategory);
Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
storeOperationFailed = true;
}
Assert.IsTrue(storeOperationFailed);
// validation: Lookup point will succeed.
PointMapping<int> pNew = lsm.GetMappingForKey(1);
Assert.IsNotNull(pNew);
}
示例11: AddPointMappingDefault
public void AddPointMappingDefault()
{
CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
countingCache,
ShardMapManagerLoadPolicy.Lazy,
new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(2, s);
Assert.IsNotNull(p1);
PointMapping<int> p2 = lsm.GetMappingForKey(2);
Assert.IsNotNull(p2);
Assert.AreEqual(0, countingCache.LookupMappingCount);
Assert.AreEqual(0, countingCache.LookupMappingHitCount);
// Validate mapping by trying to connect
using (SqlConnection conn = lsm.OpenConnection(
p1,
Globals.ShardUserConnectionString,
ConnectionOptions.Validate))
{
}
}
示例12: AddPointMappingNoCacheUpdate
public void AddPointMappingNoCacheUpdate()
{
// Create a cache store that never inserts.
CountingCacheStore cacheStore =
new CountingCacheStore(
new StubCacheStore()
{
CallBase = true,
AddOrUpdateMappingIStoreMappingCacheStoreMappingUpdatePolicy = (ssm, p) => { }
});
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
new SqlStoreConnectionFactory(),
new StoreOperationFactory(),
cacheStore,
ShardMapManagerLoadPolicy.Lazy,
RetryPolicy.DefaultRetryPolicy, RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(2, s);
Assert.IsNotNull(p1);
PointMapping<int> p2 = lsm.GetMappingForKey(2);
Assert.IsNotNull(p2);
Assert.AreEqual(0, cacheStore.LookupMappingMissCount);
}
示例13: UnavailableServerOpenConnectionForKeyListShardMapInternal
//.........这里部分代码省略.........
TimeToLiveMillisecondsGet = () => currentMapping.TimeToLiveMilliseconds,
ResetTimeToLive = () => currentMapping.ResetTimeToLive(),
HasTimeToLiveExpired = () => currentMapping.HasTimeToLiveExpired()
};
scs = new StubCacheStore()
{
CallBase = true,
LookupMappingByKeyIStoreShardMapShardKey = (_ssm, _sk) =>
{
var original = scs.LookupMappingByKeyIStoreShardMapShardKey;
scs.LookupMappingByKeyIStoreShardMapShardKey = null;
try
{
currentMapping = scs.LookupMappingByKey(_ssm, _sk);
return sics;
}
finally
{
scs.LookupMappingByKeyIStoreShardMapShardKey = original;
}
}
};
ShardMapManager smm = new ShardMapManager(
new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
scf,
sof,
scs,
ShardMapManagerLoadPolicy.Lazy,
RetryPolicy.DefaultRetryPolicy, RetryBehavior.DefaultRetryBehavior);
ListShardMap<int> lsm = smm.GetListShardMap<int>(ShardMapperTests.s_listShardMapName);
Assert.IsNotNull(lsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
Shard s = lsm.CreateShard(sl);
Assert.IsNotNull(s);
PointMapping<int> p1 = lsm.CreatePointMapping(2, s);
Assert.IsNotNull(p1);
// Mapping is there, now let's try to abort the OpenConnectionForKey
shouldThrow = true;
bool failed = false;
for (int i = 1; i <= 10; i++)
{
failed = false;
try
{
if (openConnectionAsync)
{
lsm.OpenConnectionForKeyAsync(2, Globals.ShardUserConnectionString).Wait();
}
else
{
lsm.OpenConnectionForKey(2, Globals.ShardUserConnectionString);
}
}
catch (Exception ex)
{