Ejemplo n.º 1
0
    public async Task TestInsertAfterInsertIgnoreHasRowError()
    {
        var builder = ClientTestUtil.GetBasicSchema()
                      .SetTableName(nameof(TestInsertAfterInsertIgnoreHasRowError));

        var table = await _client.CreateTableAsync(builder);

        var rows = new[]
        {
            ClientTestUtil.CreateBasicSchemaInsertIgnore(table, 1),
            ClientTestUtil.CreateBasicSchemaInsert(table, 1)
        };

        var exception = await Assert.ThrowsAsync <KuduWriteException>(
            () => _client.WriteAsync(rows));

        var rowError = Assert.Single(exception.PerRowErrors);

        Assert.True(rowError.IsAlreadyPresent);

        var rowStrings = await ClientTestUtil.ScanTableToStringsAsync(_client, table);

        var rowString = Assert.Single(rowStrings);

        Assert.Equal(
            "INT32 key=1, INT32 column1_i=2, INT32 column2_i=3, " +
            "STRING column3_s=a string, BOOL column4_b=True", rowString);
    }
Ejemplo n.º 2
0
    public async Task TestInsertIgnore()
    {
        var builder = ClientTestUtil.GetBasicSchema()
                      .SetTableName(nameof(TestInsertIgnore));

        var table = await _client.CreateTableAsync(builder);

        // Test insert ignore implements normal insert.
        var insert = ClientTestUtil.CreateBasicSchemaInsertIgnore(table, 1);
        await _client.WriteAsync(new[] { insert });

        var rowStrings = await ClientTestUtil.ScanTableToStringsAsync(_client, table);

        var rowString = Assert.Single(rowStrings);

        Assert.Equal(
            "INT32 key=1, INT32 column1_i=2, INT32 column2_i=3, " +
            "STRING column3_s=a string, BOOL column4_b=True", rowString);

        // Test insert ignore does not return a row error.
        await _client.WriteAsync(new[] { insert });

        rowStrings = await ClientTestUtil.ScanTableToStringsAsync(_client, table);

        rowString = Assert.Single(rowStrings);
        Assert.Equal(
            "INT32 key=1, INT32 column1_i=2, INT32 column2_i=3, " +
            "STRING column3_s=a string, BOOL column4_b=True", rowString);
    }
Ejemplo n.º 3
0
    public async Task TestInsertIgnoreAfterInsertHasNoRowError()
    {
        var builder = ClientTestUtil.GetBasicSchema()
                      .SetTableName(nameof(TestInsertIgnoreAfterInsertHasNoRowError));

        var table = await _client.CreateTableAsync(builder);

        var rows = new[]
        {
            ClientTestUtil.CreateBasicSchemaInsert(table, 1),
            ClientTestUtil.CreateBasicSchemaUpsert(table, 1, 1, false),
            ClientTestUtil.CreateBasicSchemaInsertIgnore(table, 1)
        };

        await _client.WriteAsync(rows);

        var rowStrings = await ClientTestUtil.ScanTableToStringsAsync(_client, table);

        var rowString = Assert.Single(rowStrings);

        Assert.Equal(
            "INT32 key=1, INT32 column1_i=1, INT32 column2_i=3, " +
            "STRING column3_s=a string, BOOL column4_b=True", rowString);
    }