public void CanEnableDataCaptureOnUpdate() { using (var context = FluentMockContext.Start(GetType().FullName)) { var region = Region.USEast; var groupName = TestUtilities.GenerateName("rgns"); var azure = TestHelper.CreateRollupClient(); try { var stgName = TestUtilities.GenerateName("stg"); var namespaceName = TestUtilities.GenerateName("ns111"); var eventHubName = TestUtilities.GenerateName("eh"); var namespaceCreatable = azure.EventHubNamespaces .Define(namespaceName) .WithRegion(region) .WithNewResourceGroup(groupName); IEventHub eventHub = azure.EventHubs .Define(eventHubName) .WithNewNamespace(namespaceCreatable) .Create(); bool exceptionThrown = false; try { eventHub.Update() .WithDataCaptureEnabled() .Apply(); } catch { exceptionThrown = true; } Assert.True(exceptionThrown, "Expected IllegalStateException is not thrown"); eventHub = eventHub.Refresh(); var storageAccountCreatable = azure.StorageAccounts .Define(stgName) .WithRegion(region) .WithNewResourceGroup(groupName) .WithSku(StorageAccountSkuType.Standard_LRS); eventHub.Update() .WithDataCaptureEnabled() .WithNewStorageAccountForCapturedData(storageAccountCreatable, "eventctr") .Apply(); Assert.True(eventHub.IsDataCaptureEnabled); Assert.NotNull(eventHub.CaptureDestination); Assert.Contains("/storageAccounts/", eventHub.CaptureDestination.StorageAccountResourceId); Assert.Contains(stgName, eventHub.CaptureDestination.StorageAccountResourceId); Assert.Equal("eventctr", eventHub.CaptureDestination.BlobContainer, ignoreCase: true); } finally { try { azure.ResourceGroups.DeleteByName(groupName); } catch { } } } }
public void CanConfigureDataCapturing() { using (var context = FluentMockContext.Start(GetType().FullName)) { var region = Region.USEast; var groupName = TestUtilities.GenerateName("rgns"); var stgName = TestUtilities.GenerateName("stg"); var namespaceName = TestUtilities.GenerateName("ns111"); var eventHubName1 = TestUtilities.GenerateName("eh"); var eventHubName2 = TestUtilities.GenerateName("eh"); var azure = TestHelper.CreateRollupClient(); try { var storageAccountCreatable = azure.StorageAccounts .Define(stgName) .WithRegion(region) .WithNewResourceGroup(groupName) .WithSku(StorageAccountSkuType.Standard_LRS); var namespaceCreatable = azure.EventHubNamespaces .Define(namespaceName) .WithRegion(region) .WithNewResourceGroup(groupName); var containerName1 = "eventsctr1"; IEventHub eventHub1 = azure.EventHubs .Define(eventHubName1) .WithNewNamespace(namespaceCreatable) .WithNewStorageAccountForCapturedData(storageAccountCreatable, containerName1) .WithDataCaptureEnabled() // Window config is optional if not set service will choose default for it2 // .WithDataCaptureWindowSizeInSeconds(120) .WithDataCaptureWindowSizeInMB(300) .Create(); Assert.NotNull(eventHub1); Assert.NotNull(eventHub1.Inner); Assert.NotNull(eventHub1.Name); Assert.Equal(eventHub1.Name, eventHubName1, ignoreCase: true); Assert.NotNull(eventHub1.PartitionIds); Assert.True(eventHub1.IsDataCaptureEnabled); Assert.NotNull(eventHub1.CaptureDestination); Assert.Contains("/storageAccounts/", eventHub1.CaptureDestination.StorageAccountResourceId); Assert.Contains(stgName, eventHub1.CaptureDestination.StorageAccountResourceId); Assert.Equal(eventHub1.CaptureDestination.BlobContainer, containerName1, ignoreCase: true); // Create another event Hub in the same namespace with data capture uses the same storage account // var stgAccountId = eventHub1.CaptureDestination.StorageAccountResourceId; var containerName2 = "eventsctr2"; IEventHub eventHub2 = azure.EventHubs .Define(eventHubName2) .WithNewNamespace(namespaceCreatable) .WithExistingStorageAccountForCapturedData(stgAccountId, containerName2) .WithDataCaptureEnabled() .Create(); Assert.True(eventHub2.IsDataCaptureEnabled); Assert.NotNull(eventHub2.CaptureDestination); Assert.Contains("/storageAccounts/", eventHub2.CaptureDestination.StorageAccountResourceId); Assert.Contains(stgName, eventHub2.CaptureDestination.StorageAccountResourceId); Assert.Equal(eventHub2.CaptureDestination.BlobContainer, containerName2, ignoreCase: true); eventHub2.Update() .WithDataCaptureDisabled() .Apply(); Assert.False(eventHub2.IsDataCaptureEnabled); } finally { try { azure.ResourceGroups.DeleteByName(groupName); } catch { } } } }