Beispiel #1
0
        public async Task ConnectTest()
        {
            // set up

            Server server = new Server
            {
                Services = { Publisher.BindService(new Plugin.Plugin(GetMockHttpMessageHandler().ToHttpClient())) },
                Ports    = { new ServerPort("127.0.0.1", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"127.0.0.1:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = GetConnectSettings();

            // act
            var response = client.Connect(request);

            // assert
            Assert.IsType <ConnectResponse>(response);

            // clean up
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #2
0
        public async Task ConnectTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginCampaigner.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = GetConnectSettings();

            // act
            var response = client.Connect(request);

            // assert
            Assert.IsType <ConnectResponse>(response);
            Assert.Equal("", response.SettingsError);
            Assert.Equal("", response.ConnectionError);
            Assert.Equal("", response.OauthError);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #3
0
        public async Task ConnectGlobalAndLocalConfigurationFileTest()
        {
            // setup
            PrepareTestEnvironment(false);
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginAunsight.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = GetConnectSettings(null, ",", null, false, true, true);

            // act
            var response = client.Connect(request);

            // assert
            Assert.IsType <ConnectResponse>(response);
            Assert.Equal("", response.SettingsError);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #4
0
        public async Task DisconnectTest()
        {
            // setup
            var mockHttp = new MockHttpMessageHandler();

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginZohoCreator.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = new DisconnectRequest();

            // act
            var response = client.Disconnect(request);

            // assert
            Assert.IsType <DisconnectResponse>(response);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #5
0
        public async Task ConnectTest()
        {
            // setup
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://creator.zoho.com/api/json/applications?scope=creatorapi&authtoken=mocktoken")
            .Respond("application/json",
                     "{\"result\":{\"application_list\":{\"applications\":[{\"application\":[{\"created_time\":\"2019-03-1305:29:27.0\",\"application_name\":\"EventManagement\",\"access\":\"private\",\"link_name\":\"event-management\",\"time_zone\":\"IST\",\"dateformat\":\"dd-MMM-yyyy\"}]}]},\"application_owner\":\"wyattroehler\"}}");

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginZohoCreator.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = GetConnectSettings();

            // act
            var response = client.Connect(request);

            // assert
            Assert.IsType <ConnectResponse>(response);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #6
0
        public static void Run()
        {
            // create new server and start it
            Server = new Grpc.Core.Server
            {
                Services = { Publisher.BindService(new Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };
            Server.Start();

            // write out the connection information for the Hashicorp plugin runner
            var output = String.Format("{0}|{1}|{2}|{3}:{4}|{5}",
                                       1, 1, "tcp", "localhost", Server.Ports.First().BoundPort, "grpc");

            Console.WriteLine(output);

            Logger.Info("Started on port " + Server.Ports.First().BoundPort);

            try
            {
                // create the config file for Sisense and restart Sisense
                var sisenseConfig = Replication.GenerateSisenseConfig();
                Replication.AddSisenseService(sisenseConfig);
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }
        }
Beispiel #7
0
        public async Task ReadStreamLimitTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginCampaigner.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var schema = GetTestSchema();

            var connectRequest = GetConnectSettings();

            var schemaRequest = new DiscoverSchemasRequest
            {
                Mode      = DiscoverSchemasRequest.Types.Mode.Refresh,
                ToRefresh = { schema }
            };

            var request = new ReadRequest()
            {
                DataVersions = new DataVersions
                {
                    JobId = "test"
                },
                JobId = "test",
                Limit = 1
            };

            // act
            client.Connect(connectRequest);
            var schemasResponse = client.DiscoverSchemas(schemaRequest);

            request.Schema = schemasResponse.Schemas[0];

            var response       = client.ReadStream(request);
            var responseStream = response.ResponseStream;
            var records        = new List <Record>();

            while (await responseStream.MoveNext())
            {
                records.Add(responseStream.Current);
            }

            // assert
            Assert.Equal(1, records.Count);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #8
0
        public async Task PrepareWriteTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSalesforce.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new PrepareWriteRequest()
            {
                Schema = new Schema
                {
                    Id         = "Account",
                    Properties =
                    {
                        new Property
                        {
                            Id    = "Id",
                            Type  = PropertyType.String,
                            IsKey = true
                        },
                        new Property
                        {
                            Id   = "Name",
                            Type = PropertyType.String
                        },
                        new Property
                        {
                            Id              = "LastModifiedDate",
                            Type            = PropertyType.Datetime,
                            IsUpdateCounter = true
                        }
                    }
                },
                CommitSlaSeconds = 1
            };

            // act
            client.Connect(connectRequest);
            var response = client.PrepareWrite(request);

            // assert
            Assert.IsType <PrepareWriteResponse>(response);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #9
0
        public async Task DiscoverSchemasRefreshTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginMockaroo.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("cclf1", "cclf1", new MockSchema
                    {
                        Count = 10,
                        Name  = "cclf1"
                    }) }
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Equal(1, response.Schemas.Count);

            var schema = response.Schemas[0];

            Assert.Equal($"cclf1", schema.Id);
            Assert.Equal("cclf1", schema.Name);
            Assert.Equal($"", schema.Query);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(17, schema.Properties.Count);

            var property = schema.Properties[0];

            Assert.Equal("field1", property.Id);
            Assert.Equal("field1", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.String, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #10
0
        public async Task DiscoverSchemasAllTest()
        {
            // setup
            PrepareTestEnvironment(false);
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginAunsight.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.All,
                SampleSize = 10
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            var schema = response.Schemas[0];

            Assert.Equal($"[{Constants.SchemaName}].[ReadDirectory_VEH_POL]", schema.Id);
            Assert.Equal("ReadDirectory_VEH_POL", schema.Name);
            Assert.Equal($"SELECT * FROM [{Constants.SchemaName}].[ReadDirectory_VEH_POL]", schema.Query);
            // Assert.Equal(Count.Types.Kind.Exact, schema.Count.Kind);
            // Assert.Equal(1000, schema.Count.Value);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(138, schema.Properties.Count);

            var property = schema.Properties[0];

            Assert.Equal("VEH.NUM", property.Id);
            Assert.Equal("VEH.NUM", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.String, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #11
0
        public async Task ReadStreamTest()
        {
            // setup

            Server server = new Server
            {
                Services = { Publisher.BindService(new Plugin.Plugin(GetMockHttpMessageHandler().ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new ReadRequest()
            {
                Schema = new Schema
                {
                    Id         = "[Customers.address]",
                    Properties =
                    {
                        new Property {
                            Id = "_id", Name = "_id", Type = PropertyType.Integer
                        },
                        new Property {
                            Id = "title", Name = "title", Type = PropertyType.String
                        }
                    },
                    Query = "query"
                },
                Limit = 2
            };

            // act
            client.Connect(connectRequest);
            var response       = client.ReadStream(request);
            var responseStream = response.ResponseStream;
            var records        = new List <Record>();

            while (await responseStream.MoveNext())
            {
                records.Add(responseStream.Current);
            }

            // assert
            Assert.Equal(5, records.Count);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #12
0
        public async Task DiscoverSchemasRefreshTableTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginBigQuery.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("`testdata`.`table1`", "testdata.table1") }
                // ToRefresh = {GetTestSchema("`testdata`.`emptytable`", "testdata.emptytable")}
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            var schema = response.Schemas[0];

            Assert.Equal($"`testdata`.`table1`", schema.Id);
            Assert.Equal("testdata.table1", schema.Name);
            Assert.Equal($"", schema.Query);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(6, schema.Properties.Count);

            //Properties is null here also
            var property = schema.Properties[0];

            Assert.Equal("col1", property.Id);
            Assert.Equal("col1", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.Integer, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #13
0
        public async Task ReadStreamTableSchemaTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginDb2.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();


            var request = new ReadRequest()
            {
                DataVersions = new DataVersions
                {
                    JobId = "test"
                },
                JobId = "test",
            };

            // act
            client.Connect(connectRequest);
            var schemas = client.DiscoverSchemas(new DiscoverSchemasRequest());

            request.Schema = schemas.Schemas.First();

            var response       = client.ReadStream(request);
            var responseStream = response.ResponseStream;
            var records        = new List <Record>();

            while (await responseStream.MoveNext())
            {
                records.Add(responseStream.Current);
            }

            // assert
            Assert.Equal(1000, records.Count);

            var record = JsonConvert.DeserializeObject <Dictionary <string, object> >(records[0].DataJson);

            Assert.Equal((long)1, record["\"ID\""]);
            Assert.Equal("Madison", record["\"FIRST_NAME\""]);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #14
0
        public async Task DiscoverSchemasRefreshTest()
        {
            // set up
            Server server = new Server
            {
                Services = { Publisher.BindService(new Plugin.Plugin(GetMockHttpMessageHandler().ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode      = DiscoverSchemasRequest.Types.Mode.Refresh,
                ToRefresh = { GetTestSchema("DiscoverSchemas") }
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            var schema = response.Schemas[0];

            Assert.Equal("test", schema.Id);
            Assert.Equal("test", schema.Name);
            Assert.Equal(2, schema.Properties.Count);

            var firstProperty = schema.Properties[0];

            Assert.Equal("_id", firstProperty.Id);
            Assert.Equal("_id", firstProperty.Name);
            Assert.Equal(PropertyType.String, firstProperty.Type);

            var secondProperty = schema.Properties[1];

            Assert.Equal("title", secondProperty.Id);
            Assert.Equal("title", secondProperty.Name);
            Assert.Equal(PropertyType.String, secondProperty.Type);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #15
0
        public async Task BeginOAuthFlowTest()
        {
            // setup
            var mockHttp = GetMockHttpMessageHandler();

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSalesforce.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = new BeginOAuthFlowRequest()
            {
                Configuration = new OAuthConfiguration
                {
                    ClientId          = "client",
                    ClientSecret      = "secret",
                    ConfigurationJson = "{}"
                },
                RedirectUrl = "http://test.com"
            };

            var clientId     = request.Configuration.ClientId;
            var responseType = "code";
            var redirectUrl  = request.RedirectUrl;
            var prompt       = "consent";
            var display      = "popup";

            var authUrl = String.Format(
                "https://test.salesforce.com/services/oauth2/authorize?client_id={0}&response_type={1}&redirect_uri={2}&prompt={3}&display={4}",
                clientId,
                responseType,
                redirectUrl,
                prompt,
                display);

            // act
            var response = client.BeginOAuthFlow(request);

            // assert
            Assert.IsType <BeginOAuthFlowResponse>(response);
            Assert.Equal(authUrl, response.AuthorizationUrl);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #16
0
        public async Task DiscoverSchemasRefreshQueryTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginMariaDB.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("test", "test", $"SELECT * FROM `classicmodels`.`customers`") }
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            var schema = response.Schemas[0];

            Assert.Equal($"test", schema.Id);
            Assert.Equal("test", schema.Name);
            Assert.Equal($"SELECT * FROM `classicmodels`.`customers`", schema.Query);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(13, schema.Properties.Count);

            var property = schema.Properties[0];

            Assert.Equal("`customerNumber`", property.Id);
            Assert.Equal("customerNumber", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.Integer, property.Type);
            Assert.True(property.IsKey);
            Assert.False(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #17
0
        public async Task DiscoverSchemasAllTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginBigQuery.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.All,
                SampleSize = 10
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Equal(8, response.Schemas.Count);

            var schema = response.Schemas[0];

            Assert.Equal($"`testdata`.`NaveegoReplicationMetaData`", schema.Id);
            Assert.Equal("testdata.NaveegoReplicationMetaData", schema.Name);
            Assert.Equal($"", schema.Query);
            Assert.Equal(2, schema.Sample.Count);
            Assert.Equal(5, schema.Properties.Count);


            var property = schema.Properties[0];

            Assert.Equal("NaveegoJobId", property.Id);
            Assert.Equal("NaveegoJobId", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.String, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #18
0
        public async Task DiscoverSchemasRefreshTableTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginCassandra.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("\"system_schema\".\"tables\"", "system_schema.tables") }
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            var schema = response.Schemas[0];

            Assert.Equal($"\"system_schema\".\"tables\"", schema.Id);
            Assert.Equal("system_schema.tables", schema.Name);
            Assert.Equal($"", schema.Query);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(20, schema.Properties.Count);

            var property = schema.Properties[0];

            Assert.Equal("bloom_filter_fp_chance", property.Id);
            Assert.Equal("bloom_filter_fp_chance", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.Float, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #19
0
        public async Task DiscoverSchemasAllTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSnowflake.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.All,
                SampleSize = 10
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Equal(1, response.Schemas.Count);

            var schema = response.Schemas[0];

            Assert.Equal($"\"PUBLIC\".\"MOCK_DATA\"", schema.Id);
            Assert.Equal("PUBLIC.MOCK_DATA", schema.Name);
            Assert.Equal($"", schema.Query);
            Assert.Equal(10, schema.Sample.Count);
            Assert.Equal(11, schema.Properties.Count);

            var property = schema.Properties[0];

            Assert.Equal("\"ID\"", property.Id);
            Assert.Equal("ID", property.Name);
            Assert.Equal("", property.Description);
            Assert.Equal(PropertyType.Text, property.Type);
            Assert.False(property.IsKey);
            Assert.True(property.IsNullable);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #20
0
        public async Task DiscoverSchemasRefreshTest()
        {
            // setup
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://creator.zoho.com/api/json/applications?scope=creatorapi&authtoken=mocktoken")
            .Respond("application/json",
                     "{\"result\":{\"application_list\":{\"applications\":[{\"application\":[{\"created_time\":\"2019-03-1305:29:27.0\",\"application_name\":\"EventManagement\",\"access\":\"private\",\"link_name\":\"event-management\",\"time_zone\":\"IST\",\"dateformat\":\"dd-MMM-yyyy\"}]}]},\"application_owner\":\"wyattroehler\"}}");

            mockHttp.When("https://creator.zoho.com/api/json/event-management/formsandviews?scope=creatorapi&zc_ownername=wyattroehler&authtoken=mocktoken")
            .Respond("application/json",
                     "{\"application-name\":[\"event-management\",{\"viewList\":[{\"viewCount\":8},{\"linkid\":71,\"componentid\":3836610000000031391,\"displayname\":\"BookEvents\",\"componentname\":\"Book_Events_Mobile\",\"formlinkname\":\"Create_New_Event\"},{\"linkid\":72,\"componentid\":3836610000000031569,\"displayname\":\"EventsCalendar\",\"componentname\":\"Events_Calendar\",\"formlinkname\":\"Create_New_Event\"},{\"linkid\":73,\"componentid\":3836610000000031573,\"displayname\":\"AllEventsList\",\"componentname\":\"All_Events_List\",\"formlinkname\":\"Create_New_Event\"},{\"linkid\":74,\"componentid\":3836610000000031577,\"displayname\":\"PaidEventBookings\",\"componentname\":\"Booked_Entries\",\"formlinkname\":\"Book_Paid_Events\"},{\"linkid\":75,\"componentid\":3836610000000031579,\"displayname\":\"FreeEventBookings\",\"componentname\":\"Booked_Free_Entries\",\"formlinkname\":\"Book_Free_Events1\"},{\"linkid\":76,\"componentid\":3836610000000031581,\"displayname\":\"AllVenues\",\"componentname\":\"All_Venues\",\"formlinkname\":\"Add_Venue\"},{\"linkid\":77,\"componentid\":3836610000000031583,\"displayname\":\"AllEventCategories\",\"componentname\":\"All_Event_Categories\",\"formlinkname\":\"Add_Event_Category\"},{\"linkid\":78,\"componentid\":3836610000000031585,\"displayname\":\"ViewAttendees\",\"componentname\":\"All_Customers\",\"formlinkname\":\"Add_Customer\"}],\"formList\":[{\"formCount\":1},{\"linkid\":49,\"displayname\":\"CreateNewEvent\",\"componentname\":\"Create_New_Event\"}]}]}");

            mockHttp.When("https://creator.zoho.com/api/json/event-management/Create_New_Event/fields?scope=creatorapi&zc_ownername=wyattroehler&authtoken=mocktoken")
            .Respond("application/json",
                     "{\"application-name\":[\"event-management\",{\"form-name\":[\"Create_New_Event\",{\"Fields\":[{\"Reqd\":true,\"Type\":100,\"Choices\":[{\"choice1\":\"3836610000000030013\"}],\"Tooltip\":\"\",\"DisplayName\":\"EventCategory\",\"Unique\":false,\"FieldName\":\"Event_Category\",\"apiType\":12},{\"Reqd\":true,\"Type\":1,\"Tooltip\":\"\",\"DisplayName\":\"EventName\",\"Unique\":false,\"MaxChar\":255,\"FieldName\":\"Event_Name\",\"Initial\":\"\",\"apiType\":1},{\"Reqd\":true,\"Type\":100,\"Choices\":[{\"choice1\":\"3836610000000030019\"}],\"Tooltip\":\"\",\"DisplayName\":\"Venue\",\"Unique\":false,\"FieldName\":\"Venue\",\"apiType\":12},{\"Reqd\":true,\"Type\":22,\"Tooltip\":\"\",\"DisplayName\":\"EventStartTime\",\"Unique\":false,\"FieldName\":\"Event_Start_Time\",\"Initial\":\"\",\"apiType\":11},{\"Reqd\":true,\"Type\":22,\"Tooltip\":\"\",\"DisplayName\":\"EventEndTime\",\"Unique\":false,\"FieldName\":\"Event_End_Time\",\"Initial\":\"\",\"apiType\":11},{\"Reqd\":false,\"Type\":31,\"Tooltip\":\"\",\"DisplayName\":\"EventID\",\"Unique\":false,\"FieldName\":\"Event_ID\",\"apiType\":9},{\"Reqd\":true,\"Type\":100,\"Choices\":[{\"choice1\":\"Free\",\"choice2\":\"Paid\"}],\"Tooltip\":\"\",\"DisplayName\":\"TicketType\",\"Unique\":false,\"FieldName\":\"Subscription_Type\",\"apiType\":12},{\"Reqd\":true,\"altTxtReq\":false,\"Type\":20,\"imgLinkReq\":false,\"imgTitleReq\":false,\"Tooltip\":\"\",\"DisplayName\":\"EventImage\",\"Unique\":false,\"FieldName\":\"Event_Image\",\"apiType\":18},{\"Reqd\":true,\"Type\":6,\"Tooltip\":\"\",\"DisplayName\":\"EntryFees\",\"Unique\":false,\"MaxChar\":10,\"FieldName\":\"Entry_Fees\",\"Initial\":\"0\",\"CurrencyType\":\"USD\",\"apiType\":8},{\"Reqd\":true,\"Type\":5,\"Tooltip\":\"\",\"DisplayName\":\"Numberofentries\",\"Unique\":false,\"MaxChar\":10,\"FieldName\":\"Number_of_entries\",\"Initial\":\"0\",\"apiType\":5},{\"Reqd\":false,\"Type\":5,\"Tooltip\":\"\",\"DisplayName\":\"AvailableEntries\",\"Unique\":false,\"MaxChar\":10,\"FieldName\":\"Available_Entries\",\"Initial\":\"0\",\"apiType\":5},{\"Reqd\":true,\"Type\":3,\"Tooltip\":\"\",\"DisplayName\":\"EventDescription\",\"Unique\":false,\"FieldName\":\"Remarks\",\"apiType\":2},{\"Reqd\":false,\"Type\":101,\"Choices\":[{\"choice1\":\"Active\",\"choice2\":\"Ended\"}],\"Tooltip\":\"\",\"DisplayName\":\"EventStatus\",\"Unique\":false,\"FieldName\":\"Event_Status\",\"apiType\":13}],\"DisplayName\":\"CreateNewEvent\"}]}]}");

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginZohoCreator.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode      = DiscoverSchemasRequest.Types.Mode.Refresh,
                ToRefresh = { new Schema {
                                  Id = "2"
                              } }
            };

            // act
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Empty(response.Schemas);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #21
0
        public async Task PrepareWriteTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginMariaDB.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new PrepareWriteRequest()
            {
                Schema           = GetTestSchema(),
                CommitSlaSeconds = 1,
                Replication      = new ReplicationWriteRequest
                {
                    SettingsJson = JsonConvert.SerializeObject(new ConfigureReplicationFormData
                    {
                        SchemaName       = "test",
                        GoldenTableName  = "gr_test",
                        VersionTableName = "vr_test"
                    })
                },
                DataVersions = new DataVersions
                {
                    JobId            = "jobUnitTest",
                    ShapeId          = "shapeUnitTest",
                    JobDataVersion   = 1,
                    ShapeDataVersion = 2
                }
            };

            // act
            client.Connect(connectRequest);
            var response = client.PrepareWrite(request);

            // assert
            Assert.IsType <PrepareWriteResponse>(response);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #22
0
        public async Task ReadStreamQueryTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSalesforce.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var discoverRequest = new DiscoverSchemasRequest
            {
                Mode      = DiscoverSchemasRequest.Types.Mode.Refresh,
                ToRefresh = { new Schema {
                                  Id = "Custom", Name = "Custom", Query = "SELECT id, name from Account"
                              } }
            };

            // act
            client.Connect(connectRequest);
            var discoverResponse = client.DiscoverSchemas(discoverRequest);

            var request = new ReadRequest()
            {
                Schema = discoverResponse.Schemas.First(),
            };

            var response       = client.ReadStream(request);
            var responseStream = response.ResponseStream;
            var records        = new List <Record>();

            while (await responseStream.MoveNext())
            {
                records.Add(responseStream.Current);
            }

            // assert
            Assert.Equal(12, records.Count);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #23
0
        public async Task DiscoverSchemasAllTest()
        {
            // setup
            var mockHttp = GetMockHttpMessageHandler();

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSalesforce.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var configureRequest = new ConfigureRequest
            {
                TemporaryDirectory = "../../../Temp",
                PermanentDirectory = "../../../Perm",
                LogDirectory       = "../../../Logs",
                DataVersions       = new DataVersions(),
                LogLevel           = LogLevel.Debug
            };

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode = DiscoverSchemasRequest.Types.Mode.All,
            };

            // act
            client.Configure(configureRequest);
            client.Connect(connectRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Equal(2, response.Schemas.Count);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #24
0
        public async Task DiscoverSchemasRefreshBadMockSchemaNameTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginMockaroo.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("id", "name", new MockSchema
                    {
                        Count = 10,
                        Name  = "bad"
                    }) }
            };

            // act
            client.Connect(connectRequest);

            try
            {
                var response = client.DiscoverSchemas(request);
            }
            catch (Exception e)
            {
                // assert
                Assert.IsType <RpcException>(e);
                Assert.Contains("Schema bad not found", e.Message);
            }

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            try
            {
                // Initialize logger
                Logger.Init();

                // Add final chance exception handler
                AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
                {
                    Logger.Error(null, $"died: {eventArgs.ExceptionObject}");
                    Logger.CloseAndFlush();
                };

                // clean old logs on start up
                Logger.Clean();

                // create new server and start it
                Server server = new Server
                {
                    Services = { Publisher.BindService(new Plugin.Plugin()) },
                    Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
                };
                server.Start();

                // write out the connection information for the Hashicorp plugin runner
                var output = String.Format("{0}|{1}|{2}|{3}:{4}|{5}",
                                           1, 1, "tcp", "localhost", server.Ports.First().BoundPort, "grpc");

                Console.WriteLine(output);

                Logger.Info("Started on port " + server.Ports.First().BoundPort);

                // wait to exit until given input
                Console.ReadLine();

                Logger.Info("Plugin exiting...");

                Logger.CloseAndFlush();
                // shutdown server
                server.ShutdownAsync().Wait();
            }
            catch (Exception e)
            {
                Logger.Error(e, e.Message);
                Logger.CloseAndFlush();
            }
        }
Beispiel #26
0
        public async Task ReadStreamLimitTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSage.Plugin.Plugin(GetMockSessionFactory())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new ReadRequest()
            {
                Schema = new Schema
                {
                    Id = "3",
                    PublisherMetaJson = "{\"Module\":\"test module\"}"
                },
                Limit = 1
            };

            // act
            client.Connect(connectRequest);
            var response       = client.ReadStream(request);
            var responseStream = response.ResponseStream;
            var records        = new List <Record>();

            while (await responseStream.MoveNext())
            {
                records.Add(responseStream.Current);
            }

            // assert
            Assert.Single(records);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #27
0
        public async Task DiscoverSchemasRefreshQueryBadSyntaxTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginBigQuery.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.Refresh,
                SampleSize = 10,
                ToRefresh  = { GetTestSchema("testdata.table1", "testdata.table1", $"bad syntax") }
            };

            // act
            client.Connect(connectRequest);

            try
            {
                var response = client.DiscoverSchemas(request);
            }
            catch (Exception e)
            {
                // assert
                Assert.IsType <RpcException>(e);

                Regex rgx    = new Regex("Job.*contained errors", RegexOptions.Compiled);
                bool  passed = rgx.IsMatch(e.Message);
                Assert.True(passed);
            }

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #28
0
        public async Task PrepareWriteTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSage.Plugin.Plugin(GetMockSessionFactory())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var request = new PrepareWriteRequest
            {
                Schema = new Schema
                {
                    Name = "test",
                    PublisherMetaJson = "{\"Module\":\"test module\"}"
                },
                CommitSlaSeconds = 1,
                DataVersions     = new DataVersions
                {
                    JobId            = "test",
                    ShapeId          = "test",
                    JobDataVersion   = 1,
                    ShapeDataVersion = 1
                }
            };

            // act
            client.Connect(connectRequest);
            var response = client.PrepareWrite(request);

            // assert
            Assert.IsType <PrepareWriteResponse>(response);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #29
0
        public async Task ConnectFailedTest()
        {
            // setup
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginMySQL.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            const string wrongUsername = "******";

            var request = new ConnectRequest
            {
                SettingsJson = JsonConvert.SerializeObject(new Settings
                {
                    Hostname = "localhost",
                    Database = "test_db",
                    Port     = "3306",
                    Username = wrongUsername,
                    Password = "******"
                }),
                OauthConfiguration = new OAuthConfiguration(),
                OauthStateJson     = ""
            };

            // act
            var response = client.Connect(request);

            // assert
            Assert.IsType <ConnectResponse>(response);
            Assert.Equal("", response.SettingsError);
            Assert.Equal($"Access denied for user '{wrongUsername}'@'172.17.0.1' (using password: YES)", response.ConnectionError);
            Assert.Equal("", response.OauthError);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }
Beispiel #30
0
        public async Task DiscoverSchemasRefreshTest()
        {
            // setup
            PrepareTestEnvironment(false);
            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginAunsight.Plugin.Plugin()) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var connectRequest = GetConnectSettings();

            var discoverAllRequest = new DiscoverSchemasRequest
            {
                Mode       = DiscoverSchemasRequest.Types.Mode.All,
                SampleSize = 10
            };

            var request = new DiscoverSchemasRequest
            {
                Mode      = DiscoverSchemasRequest.Types.Mode.Refresh,
                ToRefresh = { GetTestSchema($"SELECT * FROM [{Constants.SchemaName}].[ReadDirectory_VEH_POL]") },
            };

            // act
            client.Connect(connectRequest);
            client.DiscoverSchemas(discoverAllRequest);
            var response = client.DiscoverSchemas(request);

            // assert
            Assert.IsType <DiscoverSchemasResponse>(response);
            Assert.Single(response.Schemas);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }