mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
Add TimescaleNode subclasses for TAP Testing
Use subclassing to inherit from `PostgresNode` and create a hierarchy containing `AccessNode` and `DataNode` to simplify creating tests with multiple nodes. Also, two new functions are added: `TimescaleNode::create`: Creates the new node by calling `get_new_node`, `init` and `start` in that order. `AccessNode::add_data_node`: Adds a new data node to the access node. Also rewrite the test to use the new hierarchy.
This commit is contained in:
parent
551ac56937
commit
58b1eb83d4
21
test/perl/AccessNode.pm
Normal file
21
test/perl/AccessNode.pm
Normal file
@ -0,0 +1,21 @@
|
||||
# This file and its contents are licensed under the Timescale License.
|
||||
# Please see the included NOTICE for copyright information and
|
||||
# LICENSE-TIMESCALE for a copy of the license.
|
||||
|
||||
package AccessNode;
|
||||
use parent qw(TimescaleNode);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub add_data_node
|
||||
{
|
||||
my ($self, $dn) = @_;
|
||||
my $name = $dn->name;
|
||||
my $host = $dn->host;
|
||||
my $port = $dn->port;
|
||||
$self->safe_psql('postgres',
|
||||
"SELECT add_data_node('$name', host => '$host', port => $port)");
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
10
test/perl/DataNode.pm
Normal file
10
test/perl/DataNode.pm
Normal file
@ -0,0 +1,10 @@
|
||||
# This file and its contents are licensed under the Timescale License.
|
||||
# Please see the included NOTICE for copyright information and
|
||||
# LICENSE-TIMESCALE for a copy of the license.
|
||||
|
||||
package DataNode;
|
||||
use parent qw(TimescaleNode);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
1;
|
@ -6,7 +6,7 @@
|
||||
# routines for setup.
|
||||
|
||||
package TimescaleNode;
|
||||
use parent ("PostgresNode");
|
||||
use parent qw(PostgresNode);
|
||||
use TestLib qw(slurp_file);
|
||||
use strict;
|
||||
use warnings;
|
||||
@ -14,29 +14,13 @@ use warnings;
|
||||
use Carp 'verbose';
|
||||
$SIG{__DIE__} = \&Carp::confess;
|
||||
|
||||
use Exporter 'import';
|
||||
use vars qw(@EXPORT @EXPORT_OK);
|
||||
@EXPORT = qw(
|
||||
get_new_ts_node
|
||||
);
|
||||
@EXPORT_OK = qw(
|
||||
);
|
||||
|
||||
#
|
||||
# Get a new TS-enabled PostgreSQL instance
|
||||
#
|
||||
# It's not created yet, but ready to restore from backup,
|
||||
# initdb, etc.
|
||||
#
|
||||
sub get_new_ts_node
|
||||
sub create
|
||||
{
|
||||
my ($name, $class) = @_;
|
||||
|
||||
$class //= 'TimescaleNode';
|
||||
|
||||
my $self = PostgresNode::get_new_node($name);
|
||||
$self = bless $self, $class;
|
||||
|
||||
my ($class, $name, %kwargs) = @_;
|
||||
my $self = $class->get_new_node($name);
|
||||
$self->init(%kwargs);
|
||||
$self->start(%kwargs);
|
||||
$self->safe_psql('postgres', 'CREATE EXTENSION timescaledb');
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -5,40 +5,22 @@
|
||||
# test a simple multi node cluster creation and basic operations
|
||||
use strict;
|
||||
use warnings;
|
||||
use TimescaleNode qw(get_new_ts_node);
|
||||
use AccessNode;
|
||||
use DataNode;
|
||||
use TestLib;
|
||||
use Test::More tests => 9;
|
||||
|
||||
#Initialize all the multi-node instances
|
||||
my @nodes = ();
|
||||
foreach my $nodename ('an', 'dn1', 'dn2')
|
||||
{
|
||||
my $node = get_new_ts_node($nodename);
|
||||
$node->init;
|
||||
$node->start;
|
||||
# set up the access node
|
||||
if ($node->name eq 'an')
|
||||
{
|
||||
$node->safe_psql('postgres', "CREATE DATABASE an");
|
||||
$node->safe_psql('an', "CREATE EXTENSION timescaledb");
|
||||
}
|
||||
push @nodes, $node;
|
||||
}
|
||||
my $an = AccessNode->create('an');
|
||||
my $dn1 = DataNode->create('dn1');
|
||||
my $dn2 = DataNode->create('dn2');
|
||||
|
||||
#Add the data nodes from the access node
|
||||
foreach my $i (1 .. 2)
|
||||
{
|
||||
my $host = $nodes[$i]->host();
|
||||
my $port = $nodes[$i]->port();
|
||||
|
||||
$nodes[0]->safe_psql('an',
|
||||
"SELECT add_data_node('dn$i', database => 'dn$i', host => '$host', port => $port)"
|
||||
);
|
||||
}
|
||||
$an->add_data_node($dn1);
|
||||
$an->add_data_node($dn2);
|
||||
|
||||
#Create a distributed hypertable and insert a few rows
|
||||
$nodes[0]->safe_psql(
|
||||
'an',
|
||||
$an->safe_psql(
|
||||
'postgres',
|
||||
qq[
|
||||
CREATE TABLE test(time timestamp NOT NULL, device int, temp float);
|
||||
SELECT create_distributed_hypertable('test', 'time', 'device', 3);
|
||||
@ -49,23 +31,23 @@ $nodes[0]->safe_psql(
|
||||
my $query = q[SELECT * from show_chunks('test');];
|
||||
|
||||
#Query Access node
|
||||
$nodes[0]->psql_is(
|
||||
'an', $query, q[_timescaledb_internal._dist_hyper_1_1_chunk
|
||||
$an->psql_is(
|
||||
'postgres', $query, q[_timescaledb_internal._dist_hyper_1_1_chunk
|
||||
_timescaledb_internal._dist_hyper_1_2_chunk
|
||||
_timescaledb_internal._dist_hyper_1_3_chunk
|
||||
_timescaledb_internal._dist_hyper_1_4_chunk], 'AN shows correct set of chunks'
|
||||
);
|
||||
|
||||
#Query datanode1
|
||||
$nodes[1]->psql_is(
|
||||
'dn1',
|
||||
$dn1->psql_is(
|
||||
'postgres',
|
||||
$query,
|
||||
"_timescaledb_internal._dist_hyper_1_1_chunk\n_timescaledb_internal._dist_hyper_1_3_chunk\n_timescaledb_internal._dist_hyper_1_4_chunk",
|
||||
'DN1 shows correct set of chunks');
|
||||
|
||||
#Query datanode2
|
||||
$nodes[2]->psql_is(
|
||||
'dn2', $query,
|
||||
$dn2->psql_is(
|
||||
'postgres', $query,
|
||||
"_timescaledb_internal._dist_hyper_1_2_chunk",
|
||||
'DN2 shows correct set of chunks');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user