Example #1
0
        public void ICanCallThe_Connect_ClusterHDInsightClusterCmdlet_WithDebug()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                var logWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = logWriter;
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.UseAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                    .WithParameter(CmdletConstants.Debug, null)
                    .Invoke();

                Assert.AreEqual(1, results.Results.Count);
                IAzureHDInsightConnectionSessionManager sessionManager =
                    ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null);
                AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster();
                Assert.IsNotNull(currentCluster);
                string expectedLogMessage = "Getting hdinsight clusters for subscriptionid : ";
                ValidateGetCluster(currentCluster.Cluster);
                Assert.IsTrue(logWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();
            }
        }
Example #2
0
        public void ICanCallThe_Connect_ClusterHDInsightClusterCmdlet_MoreThanOnce()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                IHDInsightCertificateCredential credentials = GetValidCredentials();
                IPipelineResult clusterResults =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GetAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                    .Invoke();
                IEnumerable <AzureHDInsightCluster> clusters = clusterResults.Results.ToEnumerable <AzureHDInsightCluster>();
                foreach (AzureHDInsightCluster cluster in clusters)
                {
                    IPipelineResult results =
                        runspace.NewPipeline()
                        .AddCommand(CmdletConstants.UseAzureHDInsightCluster)
                        .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                        .Invoke();
                    Assert.AreEqual(1, results.Results.Count);
                    IAzureHDInsightConnectionSessionManager sessionManager =
                        ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null);
                    AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster();
                    Assert.IsNotNull(currentCluster);
                    ValidateGetCluster(cluster, currentCluster.Cluster);
                }
            }
        }
        public IAzureHDInsightConnectionSessionManager Create(SessionState sessionState)
        {
            if (singleton == null)
            {
                singleton = new AzureHDInsightConnectionSessionManagerSimulator();
            }

            return singleton;
        }
Example #4
0
        public IAzureHDInsightConnectionSessionManager Create(SessionState sessionState)
        {
            if (singleton == null)
            {
                singleton = new AzureHDInsightConnectionSessionManagerSimulator();
            }

            return(singleton);
        }
        private static void ConnectToCluster(IRunspace runspace, IHDInsightCertificateCredential creds)
        {
            IPipelineResult results =
                runspace.NewPipeline()
                .AddCommand(CmdletConstants.UseAzureHDInsightCluster)
                .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                .Invoke();

            Assert.AreEqual(1, results.Results.Count);
            IAzureHDInsightConnectionSessionManager sessionManager =
                ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null);
            AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster();

            ValidateGetCluster(currentCluster.Cluster);
        }
Example #6
0
        public static AzureHDInsightClusterConnection AssertValidConnection(this PSCmdlet cmdlet)
        {
            IAzureHDInsightConnectionSessionManager sessionManager =
                ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(cmdlet.SessionState);
            AzureHDInsightClusterConnection currentConnection = sessionManager.GetCurrentCluster();

            if (currentConnection == null)
            {
                cmdlet.ThrowTerminatingError(
                    new ErrorRecord(
                        new NotSupportedException("Please connect to a valid Azure HDInsight cluster before calling this cmdlet."),
                        "1024",
                        ErrorCategory.ConnectionError,
                        cmdlet));
            }

            return(currentConnection);
        }
        public void CannotCallTheExecHiveCmdlet_WithoutConnecting()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                try
                {
                    IAzureHDInsightConnectionSessionManager sessionManager =
                        ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null);
                    sessionManager.SetCurrentCluster(null);

                    runspace.NewPipeline().AddCommand(CmdletConstants.InvokeHive).WithParameter(CmdletConstants.Query, "show tables").Invoke();
                    Assert.Fail("test failed.");
                }
                catch (CmdletInvocationException cmdException)
                {
                    Assert.AreEqual(cmdException.ErrorRecord.CategoryInfo.Category, ErrorCategory.ConnectionError);
                }
            }
        }