Esempio n. 1
0
    public async Task InitializeAsync()
    {
        _harness = await new MiniKuduClusterBuilder().BuildHarnessAsync();
        _client  = _harness.CreateClient();
        await using var session = _client.NewSession();

        // Create a 4-tablets table for scanning.
        var builder = new TableBuilder(_tableName)
                      .AddColumn("key1", KuduType.String, opt => opt.Key(true))
                      .AddColumn("key2", KuduType.String, opt => opt.Key(true))
                      .AddColumn("val", KuduType.String)
                      .SetRangePartitionColumns("key1", "key2");

        for (int i = 1; i < 4; i++)
        {
            builder.AddSplitRow(splitRow =>
            {
                splitRow.SetString("key1", i.ToString());
                splitRow.SetString("key2", "");
            });
        }

        var table = await _client.CreateTableAsync(builder);

        // The data layout ends up like this:
        // tablet '', '1': no rows
        // tablet '1', '2': '111', '122', '133'
        // tablet '2', '3': '211', '222', '233'
        // tablet '3', '': '311', '322', '333'
        var keys = new[] { "1", "2", "3" };

        foreach (var key1 in keys)
        {
            foreach (var key2 in keys)
            {
                var insert = table.NewInsert();
                insert.SetString(0, key1);
                insert.SetString(1, key2);
                insert.SetString(2, key2);
                await session.EnqueueAsync(insert);

                await session.FlushAsync();
            }
        }

        _beforeWriteTimestamp = _client.LastPropagatedTimestamp;

        // Reset the client in order to clear the propagated timestamp.
        _newClient = _harness.CreateClient();

        // Reopen the table using the new client.
        _table = await _newClient.OpenTableAsync(_tableName);

        _schema = _table.Schema;
    }
Esempio n. 2
0
    public async Task TestExceptionCallback()
    {
        int numCallbacks = 0;
        SessionExceptionContext sessionContext = null;

        var builder = ClientTestUtil.GetBasicSchema()
                      .SetTableName(nameof(TestExceptionCallback));

        var table = await _client.CreateTableAsync(builder);

        var row1 = ClientTestUtil.CreateBasicSchemaInsert(table, 1);
        var row2 = ClientTestUtil.CreateBasicSchemaInsert(table, 1);

        var sessionOptions = new KuduSessionOptions
        {
            ExceptionHandler = HandleSessionExceptionAsync
        };

        await using var session = _client.NewSession(sessionOptions);

        await session.EnqueueAsync(row1);

        await session.FlushAsync();

        await session.EnqueueAsync(row2);

        await session.FlushAsync();

        ValueTask HandleSessionExceptionAsync(SessionExceptionContext context)
        {
            numCallbacks++;
            sessionContext = context;
            return(new ValueTask());
        }

        Assert.Equal(1, numCallbacks);

        var errorRow = Assert.Single(sessionContext.Rows);

        Assert.Same(row2, errorRow);

        var exception    = Assert.IsType <KuduWriteException>(sessionContext.Exception);
        var exceptionRow = Assert.Single(exception.PerRowErrors);

        Assert.True(exceptionRow.IsAlreadyPresent);
    }
Esempio n. 3
0
    public async Task TestMultipleSessions()
    {
        int numTasks = 60;
        var tasks    = new List <Task>(numTasks);

        var builder = ClientTestUtil.GetBasicSchema()
                      .SetTableName("TestMultipleSessions")
                      .CreateBasicRangePartition();

        var table = await _client.CreateTableAsync(builder);

        using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
        var token = cts.Token;

        for (int i = 0; i < numTasks; i++)
        {
            var task = Task.Run(async() =>
            {
                while (!token.IsCancellationRequested)
                {
                    await using var session = _client.NewSession();

                    for (int j = 0; j < 100; j++)
                    {
                        var row = table.NewUpsert();
                        row.SetInt32(0, j);
                        row.SetInt32(1, 12345);
                        row.SetInt32(2, 3);
                        row.SetNull(3);
                        row.SetBool(4, false);
                        await session.EnqueueAsync(row);
                    }
                }
            });

            tasks.Add(task);
        }

        await Task.WhenAll(tasks);
    }
Esempio n. 4
0
 public async Task InitializeAsync()
 {
     _harness = await new MiniKuduClusterBuilder().BuildHarnessAsync();
     _client  = _harness.CreateClient();
     _session = _client.NewSession();
 }