AnyEvent-InfluxDB

 view release on metacpan or  search on metacpan

xt/influxdb.t  view on Meta::CPAN

    $cv = AE::cv;
    $db->ping(
        on_success => $cv,
        on_error => sub {
            $cv->croak("Failed to ping database: @_");
        }
    );
    my $version;
    eval {
     $version = $cv->recv;
    };
    if ( $version ) {
        plan tests => 62;
        ok(1, "Connected to InfluxDB server version $version at: ". $db->server);
    } else {
        plan skip_all => 'InfluxDB server not found at: '. $db->server;
    }
}
{
    note "=== create_database ===";
    $cv = AE::cv;
    $db->create_database(
        database => "mydb",
        on_success => sub { $cv->send("test ok") },
        on_error => sub {
            $cv->croak("Failed to create database: @_");
        }
    );
    ok($cv->recv, "database mydb created");
}
{
    note "=== create_database ===";
    $cv = AE::cv;
    $db->create_database(
        database => "foo",
        on_success => sub { $cv->send("test ok") },
        on_error => sub {
            $cv->croak("Failed to create database: @_");
        }
    );
    ok($cv->recv, "database foo created");
}
{
    note "=== show_databases ===";
    $cv = AE::cv;
    $db->show_databases(
        on_success => $cv,
        on_error => sub {
            $cv->croak("Failed to list databases: @_");
        }
    );
    my @db_names = $cv->recv;
    Test::More::note "@db_names";
    is_deeply( [ sort @db_names ], [qw( _internal foo mydb )], "databases listed");
}
{
    note "=== create_database ===";
    $cv = AE::cv;
    $db->create_database(
        database => "mydb",
        if_not_exists => 1,
        on_success => sub { $cv->send("test ok") },
        on_error => sub {
            $cv->croak("Failed to create database: @_");
        }
    );
    ok($cv->recv, "database already exists, but that's ok");
}
{
    note "=== create_retention_policy ===";
    $cv = AE::cv;
    $db->create_retention_policy(
        name => 'last_day',
        database => 'mydb',
        duration => '1d',
        shard_duration => '12h',
        replication => 1,
        default => 0,

        on_success => sub { $cv->send("test ok") },
        on_error => sub {
            $cv->croak("Failed to create retention policy: @_");
        }
    );
    ok($cv->recv, "rp last_day created");
}
{
    note "=== alter_retention_policy ===";
    $cv = AE::cv;
    $db->alter_retention_policy(
        name => 'last_day',
        database => 'mydb',

        duration => '2d',
        replication => 1,
        default => 0,

        on_success => sub { $cv->send("test ok") },
        on_error => sub {
            $cv->croak("Failed to alter retention policy: @_");
        }
    );
    ok($cv->recv, "rp last_day altered");
}
{
    note "=== show_retention_policies ===";
    $cv = AE::cv;
    $db->show_retention_policies(
        database => 'mydb',

        on_success => $cv,
        on_error => sub {
            $cv->croak("Failed to list retention policies: @_");
        }
    );
    my @retention_policies = $cv->recv;
    is_deeply(
        [ @retention_policies ],
        [
            { name => "autogen", duration => 0, shardGroupDuration => '168h0m0s', replicaN => 1, default => $true },
            { name => "last_day", duration => "48h0m0s", shardGroupDuration => '12h0m0s', replicaN => 1, default => $false },



( run in 2.168 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )