Esempio n. 1
0
        public async Task WhenParallelisationShouldSucceed()
        {
            await using var conn = new SparkConnection(Config.ConnectionString);
            await conn.OpenAsync();

            var tableName = DataFactory.TableName();

            int order = 0;
            await DataFactory.DropAndCreateTable(conn, tableName, new[] { "order INT", "value INT" });

            await Task.WhenAll(Enumerable.Range(1, 5).Select(async _ =>
            {
                await using var insertConn = new SparkConnection(Config.ConnectionString);
                await insertConn.OpenAsync().ConfigureAwait(false);
                await Task.WhenAll(Enumerable.Range(1, 5).Select(async i =>
                {
                    var values = string.Join(",", Enumerable.Range(1, 40000).Select(i => $"({ Interlocked.Increment(ref order)}, {i})"));
                    await insertConn.ExecuteAsync($"INSERT INTO {tableName} VALUES {values}").ConfigureAwait(false);
                }));
            }).ToArray());


            var result = await conn.QueryAsync <int?>($"SELECT value FROM {tableName} ORDER BY random()");

            var resultList = result.ToList();

            Assert.Equal(1000000, resultList.Count);
        }
Esempio n. 2
0
        public async Task WhenNullFirstOfManyItemsShouldReturn()
        {
            await using var conn = new SparkConnection(Config.ConnectionString);
            await conn.OpenAsync();

            var tableName = DataFactory.TableName();
            int order     = 0;
            await DataFactory.DropAndCreateTable(conn, tableName, new[] { "order INT", "value INT" });

            await conn.ExecuteAsync($"INSERT INTO {tableName} VALUES ({order++}, null)");

            Task.WaitAll(Enumerable.Range(1, 16).Select(i =>
                                                        conn.ExecuteAsync($"INSERT INTO {tableName} VALUES ({Interlocked.Increment(ref order)}, {i})")
                                                        ).ToArray());

            var result = await conn.QueryAsync <int?>($"SELECT value FROM {tableName} ORDER BY order");

            var resultList = result.ToList();

            Assert.Equal(17, resultList.Count);
            Assert.Equal(new int?[] { null }.Concat(Enumerable.Range(1, 16).Cast <int?>()).ToList(), resultList);
        }
Esempio n. 3
0
        public async Task WhenParameterMissingShouldThrow()
        {
            var table = DataFactory.TableName();

            await using var conn = new SparkConnection(Config.ConnectionString);
            await conn.OpenAsync();

            await DataFactory.DropAndCreateTable(conn, table, new[] { "myString STRING NOT NULL" });

            var ex = await Assert.ThrowsAsync <MissingParameterException>(() => conn.ExecuteAsync($@"INSERT INTO {table} VALUES (@DoesNotExist)", new
            {
                DoesExist = "test"
            }));

            Assert.Equal("DoesNotExist", ex.ParameterName);
        }
Esempio n. 4
0
        public async Task WhenDapperShouldExecute()
        {
            var timestamp = new DateTime(2055, 3, 1, 21, 33, 43, 432);
            var date      = new DateTime(2055, 3, 1, 21, 33, 43, 432).Date;

            var table = DataFactory.TableName();

            await using var conn = new SparkConnection(Config.ConnectionString);
            await conn.OpenAsync();

            await DataFactory.DropAndCreateTable(conn, table, TypeRainbow.TableColumns);

            await conn.ExecuteAsync($@"INSERT INTO {table} VALUES 
                    (
                        @MyBigInt, 
                        @MyInt, 
                        @MySmallInt, 
                        @MyTinyInt, 
                        @MyBoolean,
                        @MyDouble, 
                        @MyFloat, 
                        @MyDecimal,
                        @MyString,
                        @MyDate,
                        @MyTimestamp,
                        @MyBinary,
                        array('AAA', 'BBB', 'CCC'),
                        map('AAA', 1, 'BBB', 2, 'CCC', 3)
                    )", new TypeRainbow()
            {
                MyBigInt    = Int64.MaxValue,
                MyInt       = Int32.MaxValue,
                MySmallInt  = Int16.MaxValue,
                MyTinyInt   = Byte.MaxValue,
                MyBoolean   = true,
                MyDouble    = 99999999.99d,
                MyFloat     = 99999999.99f,
                MyDecimal   = 99999999.99m,
                MyString    = "AAA",
                MyDate      = date,
                MyTimestamp = timestamp,
                MyBinary    = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }
            });

            var results = await conn.QueryAsync <TypeRainbow>($"SELECT * FROM {table}");

            var result = Assert.Single(results);

            Assert.Equal(Int64.MaxValue, result.MyBigInt);
            Assert.Equal(Int32.MaxValue, result.MyInt);
            Assert.Equal(Int16.MaxValue, result.MySmallInt);
            Assert.Equal(Byte.MaxValue, result.MyTinyInt);
            Assert.True(result.MyBoolean);
            Assert.Equal(99999999.99d, result.MyDouble);
            Assert.Equal(99999999.99f, result.MyFloat);
            Assert.Equal(99999999.99m, result.MyDecimal);
            Assert.Equal("AAA", result.MyString);
            Assert.Equal(date, result.MyDate);
            Assert.Equal(timestamp, result.MyTimestamp);
            Assert.Equal(new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }, result.MyBinary);
            Assert.Equal(@"[""AAA"",""BBB"",""CCC""]", result.MyArray);
            Assert.Equal(@"{""AAA"":1,""BBB"":2,""CCC"":3}", result.MyMap);
        }