EV-ClickHouse

 view release on metacpan or  search on metacpan

t/13_params_uri.t  view on Meta::CPAN

# Test 11-12: last_query_id
with_native(
    tests => 2,
    cb    => sub {
        $ch->query(
            "select 1",
            { query_id => 'test_qid_123' },
            sub {
                my ($rows, $err) = @_;
                ok(!$err, 'last_query_id: no error');
                is($ch->last_query_id, 'test_qid_123', 'last_query_id: correct');
                EV::break;
            },
        );
    },
);

# Test 13: last_query_id undef before any query
with_native(
    tests => 1,
    cb    => sub {
        ok(!defined $ch->last_query_id, 'last_query_id: undef initially');
        EV::break;
    },
);

# Test 14-16: on_trace callback
with_native(
    tests => 3,
    cb    => sub {
        my @traces;
        $ch->on_trace(sub { push @traces, $_[0] });
        $ch->query("select 1", sub {
            my ($rows, $err) = @_;
            ok(!$err, 'on_trace: no error');
            ok(@traces >= 1, 'on_trace: got trace messages (' . scalar(@traces) . ')');
            like($traces[0], qr/dispatch/, 'on_trace: dispatch message');
            EV::break;
        });
    },
);

# Test 17-19: Int256 type
with_native(
    tests => 3,
    cb    => sub {
        $ch->query("select toInt256(12345678901234567890) as big", sub {
            my ($rows, $err) = @_;
            ok(!$err, 'Int256: no error');
            is($rows->[0][0], '12345678901234567890', 'Int256: correct value');
        });
        # Also test UInt256
        $ch->query("select toUInt256('99999999999999999999') as big", sub {
            my ($rows, $err) = @_;
            is($rows->[0][0], '99999999999999999999', 'UInt256: correct value');
        });
        $ch->drain(sub { EV::break });
    },
);

# Test 20-22: Keepalive (just verify it doesn't crash and connection stays alive)
SKIP: {
    skip "Native port not reachable", 3 unless $nat_ok;
    my ($ka_ch, $ka_wait);
    $ka_ch = EV::ClickHouse->new(
        host       => $host,
        port       => $nat_port,
        protocol   => 'native',
        keepalive  => 1,
        on_connect => sub {
            ok(1, 'keepalive: connected');
            # Wait a bit, then query
            $ka_wait = EV::timer(0.5, 0, sub {
                ok($ka_ch->is_connected, 'keepalive: still connected');
                $ka_ch->query("select 1", sub {
                    my ($rows, $err) = @_;
                    ok(!$err, 'keepalive: query after wait ok');
                    EV::break;
                });
            });
        },
        on_error => sub { diag("KA error: $_[0]"); EV::break },
    );
    my $timeout = EV::timer(10, 0, sub { EV::break });
    EV::run;
    $ka_ch->finish if $ka_ch && $ka_ch->is_connected;
}



( run in 1.527 second using v1.01-cache-2.11-cpan-98e64b0badf )