/// <summary> /// Create the contents of the RTable configuration, and upload it to the appropriate container and blob. /// </summary> private void UploadRTableConfigToBlob(int viewId, bool convertXStoreTableMode, int numberOfBlobs) { string blobName = this.configurationInfos.FirstOrDefault().BlobPath; int index = blobName.IndexOf("/"); blobName = blobName.Substring(index + 1); // +1 to acording for "/" Console.WriteLine("Uploading RTable config ..."); for (int blobIndex = 0; blobIndex < numberOfBlobs; blobIndex++) { string connectionString; CloudBlobClient cloudBloblClient = this.GenerateCloudBlobClient( this.rtableTestConfiguration.StorageInformation.AccountNames[blobIndex], this.rtableTestConfiguration.StorageInformation.AccountKeys[blobIndex], this.rtableTestConfiguration.StorageInformation.DomainName, out connectionString); CloudBlobContainer container = cloudBloblClient.GetContainerReference(this.rtableTestConfiguration.RTableInformation.ContainerName); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); ReplicatedTableConfigurationStore configuration = this.GetRTableConfiguration(viewId, convertXStoreTableMode); string jsonConfigText = JsonStore <ReplicatedTableConfigurationStore> .Serialize(configuration); blockBlob.UploadText(jsonConfigText); } }
/// <summary> /// Modify the contents of the RTable configuration blob to use the updated viewId /// </summary> /// <param name="updatedViewId"></param> /// <param name="convertXStoreTableMode"></param> /// <param name="readViewHeadIndex"></param> private void ModifyConfigurationBlob(long updatedViewId, bool convertXStoreTableMode, int readViewHeadIndex, List <int> blobIndexes) { try { foreach (var blobIndex in blobIndexes) { Console.WriteLine("ModifyConfigurationBlob#{0} ...", blobIndex); string blobName = this.configurationInfos[blobIndex].BlobPath; int index = blobName.IndexOf("/"); blobName = blobName.Substring(index + 1); // +1 to acording for "/" Console.WriteLine("Configuration blobname = {0}", blobName); string connectionString; CloudBlobClient cloudBloblClient = this.GenerateCloudBlobClient( this.rtableTestConfiguration.StorageInformation.AccountNames[blobIndex], this.rtableTestConfiguration.StorageInformation.AccountKeys[blobIndex], this.rtableTestConfiguration.StorageInformation.DomainName, out connectionString); CloudBlobContainer container = cloudBloblClient.GetContainerReference( this.rtableTestConfiguration.RTableInformation.ContainerName); CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); string currentConfigText = blockBlob.DownloadText(); Console.WriteLine("currentConfigText = {0}", currentConfigText); ReplicatedTableConfigurationStore configuration = this.GetRTableConfiguration(updatedViewId, convertXStoreTableMode, readViewHeadIndex); string updatedConfigText = JsonStore <ReplicatedTableConfigurationStore> .Serialize(configuration); Console.WriteLine("updatedConfigText = {0}", updatedConfigText); blockBlob.UploadText(updatedConfigText); } } catch (Exception ex) { Console.WriteLine("ModifyConfigurationBlob() encountered exception {0}", ex.ToString()); throw; } }
public void DeserializeJsonConfig() { ReplicatedTableConfigurationStore conf; string jsonConf = null; // - Empty chain jsonConf = @"{'ConvertXStoreTableMode': true, 'LeaseDuration': 60, 'ReadViewHeadIndex': 1, 'ReplicaChain': '', 'Timestamp': '/Date(1460152261966)/', 'ViewId': 58}"; conf = JsonStore <ReplicatedTableConfigurationStore> .Deserialize(jsonConf); Assert.True(conf.ViewId == 58); Assert.IsTrue(conf.ReplicaChain != null); Assert.IsTrue(conf.ReplicaChain.Count == 0); jsonConf = @"{'ConvertXStoreTableMode': true, 'LeaseDuration': 60, 'ReadViewHeadIndex': 1, 'ReplicaChain': [], 'Timestamp': '/Date(1460152261966)/', 'ViewId': 58}"; conf = JsonStore <ReplicatedTableConfigurationStore> .Deserialize(jsonConf); Assert.True(conf.ViewId == 58); Assert.IsTrue(conf.ReplicaChain != null); Assert.IsTrue(conf.ReplicaChain.Count == 0); string configPath = null; //- Read legacy V1 config configPath = Directory.GetCurrentDirectory() + "\\" + @"..\Tests\ConfigFiles\V1ConfigLegacy.txt"; try { using (StreamReader sr = new StreamReader(configPath)) { conf = JsonStore <ReplicatedTableConfigurationStore> .Deserialize(sr.ReadToEnd()); Assert.True(conf.ViewId == 58); Assert.IsTrue(conf.ReplicaChain != null); Assert.IsTrue(conf.ReplicaChain.Count == 2); } } catch (Exception ex) { Assert.Fail("#Test1 - Received exception {0} while parsing {1}", ex.Message, configPath); } //- Read V1 config with extra attribute (add as part of V2 enhancements) configPath = Directory.GetCurrentDirectory() + "\\" + @"..\Tests\ConfigFiles\V1ConfigWithV2Attributes.txt"; try { using (StreamReader sr = new StreamReader(configPath)) { conf = JsonStore <ReplicatedTableConfigurationStore> .Deserialize(sr.ReadToEnd()); Assert.True(conf.ViewId == 58); Assert.IsTrue(conf.ReplicaChain != null); Assert.IsTrue(conf.ReplicaChain.Count == 2); } } catch (Exception ex) { Assert.Fail("#Test2 - Received exception {0} while parsing {1}", ex.Message, configPath); } //- Read V1 config with extra attribute (add as part of V2 enhancements) configPath = Directory.GetCurrentDirectory() + "\\" + @"..\Tests\ConfigFiles\V1ConfigWithV2AttributesWithoutAccKey.txt"; try { using (StreamReader sr = new StreamReader(configPath)) { conf = JsonStore <ReplicatedTableConfigurationStore> .Deserialize(sr.ReadToEnd()); Assert.True(conf.ViewId == 58); Assert.IsTrue(conf.ReplicaChain != null); Assert.IsTrue(conf.ReplicaChain.Count == 2); } } catch (Exception ex) { Assert.Fail("#Test2 - Received exception {0} while parsing {1}", ex.Message, configPath); } }