Exemplo n.º 1
0
        public void TableIngressEgressBatch()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableBatchOperation batch       = new TableBatchOperation();

            for (int m = 0; m < 100; m++)
            {
                // Insert Entity
                DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", m.ToString());
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[30 * 1024]));
                batch.InsertOrMerge(insertEntity);
            }

            // APM
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains("$batch"), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.EndExecuteBatch(currentTable.BeginExecuteBatch(batch, new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext, null, null));
                return(opContext.LastResult);
            });

            // SYNC
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains("$batch"), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.ExecuteBatch(batch, new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext);
                return(opContext.LastResult);
            });
        }
Exemplo n.º 2
0
        public void TableIngressEgressTableOperation()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", "foo");

            for (int m = 0; m < 20; m++)
            {
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[50 * 1024]));
            }

            // APM
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(currentTable.Uri.ToString()), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.EndExecute(currentTable.BeginExecute(TableOperation.InsertOrMerge(insertEntity), new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext, null, null));
                return(opContext.LastResult);
            });

            // Sync
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(currentTable.Uri.ToString()), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.Execute(TableOperation.InsertOrMerge(insertEntity), new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext);
                return(opContext.LastResult);
            });
        }
Exemplo n.º 3
0
        public void TableIngressEgressACLs()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            CloudTable tbl = tableClient.GetTableReference(GenerateRandomTableName());

            tbl.CreateIfNotExists();

            try
            {
                TablePermissions perms = new TablePermissions();

                // Add a policy, check setting and getting.
                perms.SharedAccessPolicies.Add(Guid.NewGuid().ToString(), new SharedAccessTablePolicy
                {
                    Permissions            = SharedAccessTablePermissions.Query,
                    SharedAccessStartTime  = DateTimeOffset.Now - TimeSpan.FromHours(1),
                    SharedAccessExpiryTime = DateTimeOffset.Now + TimeSpan.FromHours(1)
                });

                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(tbl.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    tbl.EndSetPermissions(tbl.BeginSetPermissions(perms, new TableRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext, null, null));
                    return(opContext.LastResult);
                });

                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(tbl.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    tbl.EndGetPermissions(tbl.BeginGetPermissions(new TableRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext, null, null));
                    return(opContext.LastResult);
                });
            }
            finally
            {
                tbl.DeleteIfExists();
            }
        }
Exemplo n.º 4
0
        public void TableIngressEgressQuery()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableBatchOperation batch       = new TableBatchOperation();

            for (int m = 0; m < 100; m++)
            {
                // Insert Entity
                DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", m.ToString());
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[30 * 1024]));
                batch.Insert(insertEntity, true);
            }

            currentTable.ExecuteBatch(batch);
            TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "insert test"));

            // APM
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(currentTable.Uri.ToString()), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.EndExecuteQuerySegmented(currentTable.BeginExecuteQuerySegmented(query, null, new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext, null, null));
                return(opContext.LastResult);
            });

            // SYNC
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(currentTable.Uri.ToString()), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.ExecuteQuerySegmented(query, null, new TableRequestOptions()
                {
                    RetryPolicy = new RetryPolicies.NoRetry()
                }, opContext);
                return(opContext.LastResult);
            });
        }
        public void BlobIngressEgressCounters()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            container.CreateIfNotExists();
            CloudBlockBlob blob = container.GetBlockBlobReference("blob1");

            string[] blockIds = new string[] { Convert.ToBase64String(Guid.NewGuid().ToByteArray()), Convert.ToBase64String(Guid.NewGuid().ToByteArray()), Convert.ToBase64String(Guid.NewGuid().ToByteArray()) };
            try
            {
                // 1 byte
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[0], new MemoryStream(GetRandomBuffer(1)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // 1024
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[1], new MemoryStream(GetRandomBuffer(1024)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // 98765
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[2], new MemoryStream(GetRandomBuffer(98765)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // PutBlockList
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlockList(blockIds, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // GetBlockList
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.DownloadBlockList(BlockListingFilter.All, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // Download
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.DownloadToStream(Stream.Null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                Assert.AreEqual(blob.Properties.Length, 98765 + 1024 + 1);

                // Error Case
                CloudBlockBlob   nullBlob     = container.GetBlockBlobReference("null");
                OperationContext errorContext = new OperationContext();
                try
                {
                    nullBlob.DownloadToStream(Stream.Null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, errorContext);
                    Assert.Fail("Null blob, null stream, no download possible.");
                }
                catch (StorageException)
                {
                    Assert.IsTrue(errorContext.LastResult.IngressBytes > 0);
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }