Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
PERL-582 Rename _URI member 'hostpairs' to 'hostids'
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassi committed Aug 16, 2016
1 parent 9371c8d commit a4c9a59
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion devel/t-dynamic/AUTH-MONGODB-CR.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ENV{MONGOD} = $orc->as_uri;
diag "MONGOD: $ENV{MONGOD}";

my $uri = MongoDB::_URI->new( uri => $ENV{MONGOD} );
my $no_auth_string = "mongodb://" . $uri->hostpairs->[0];
my $no_auth_string = "mongodb://" . $uri->hostids->[0];

subtest "no authentication" => sub {
my $conn = build_client( host => $no_auth_string, dt_type => undef );
Expand Down
2 changes: 1 addition & 1 deletion devel/t-dynamic/AUTH-SCRAM.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ENV{MONGOD} = $orc->as_uri;
diag "MONGOD: $ENV{MONGOD}";

my $uri = MongoDB::_URI->new( uri => $ENV{MONGOD} );
my $no_auth_string = "mongodb://" . $uri->hostpairs->[0];
my $no_auth_string = "mongodb://" . $uri->hostids->[0];

subtest "no authentication" => sub {
my $conn = build_client( host => $no_auth_string, dt_type => undef );
Expand Down
2 changes: 1 addition & 1 deletion devel/t-dynamic/AUTH-X509.t
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ diag "MONGOD: $ENV{MONGOD}";
#--------------------------------------------------------------------------#

my $uri = MongoDB::_URI->new( uri => $ENV{MONGOD} );
my $no_auth_string = "mongodb://" . $uri->hostpairs->[0];
my $no_auth_string = "mongodb://" . $uri->hostids->[0];

subtest "invalid client" => sub {
my $conn = build_client(
Expand Down
2 changes: 1 addition & 1 deletion devel/t-dynamic/AUTH-op-errors.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ENV{MONGOD} = $orc->as_uri;
diag "MONGOD: $ENV{MONGOD}";

my $uri = MongoDB::_URI->new( uri => $ENV{MONGOD} );
my $no_auth_string = "mongodb://" . $uri->hostpairs->[0];
my $no_auth_string = "mongodb://" . $uri->hostids->[0];

# This file is for testing operations that fail when unauthorized. It uses
# two client connections, one with root permissions ($alice) and one with
Expand Down
4 changes: 2 additions & 2 deletions lib/MongoDB/MongoClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ sub _build__topology {

my $type =
length( $self->replica_set_name ) ? 'ReplicaSetNoPrimary'
: @{ $self->_uri->hostpairs } > 1 ? 'Sharded'
: @{ $self->_uri->hostids } > 1 ? 'Sharded'
: 'Single';

MongoDB::_Topology->new(
Expand Down Expand Up @@ -1215,7 +1215,7 @@ sub BUILD {

my $uri = $self->_uri;

my @addresses = @{ $uri->hostpairs };
my @addresses = @{ $uri->hostids };

# resolve and validate all deferred attributes
$self->$_ for @deferred_options;
Expand Down
4 changes: 2 additions & 2 deletions lib/MongoDB/_Topology.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ has rtt_ewma_sec => (

sub _build_number_of_seeds {
my ($self) = @_;
return scalar @{ $self->uri->hostpairs };
return scalar @{ $self->uri->hostids };
}

sub BUILD {
my ($self) = @_;
my $type = $self->type;
my @addresses = @{ $self->uri->hostpairs };
my @addresses = @{ $self->uri->hostids };

# clone bson codec to disable dt_type
$self->{bson_codec} = $self->bson_codec->clone( dt_type => undef );
Expand Down
14 changes: 7 additions & 7 deletions lib/MongoDB/_URI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ has options => (
default => sub { {} },
);

has hostpairs => (
has hostids => (
is => 'ro',
isa => ArrayRef,
writer => '_set_hostpairs',
writer => '_set_hostids',
default => sub { [] },
);

Expand Down Expand Up @@ -141,18 +141,18 @@ sub BUILD {

if ($uri =~ m{^$uri_re$}) {

($result{username}, $result{password}, $result{hostpairs}, $result{db_name}, $result{options}) = ($1, $2, $3, $4, $5);
($result{username}, $result{password}, $result{hostids}, $result{db_name}, $result{options}) = ($1, $2, $3, $4, $5);

# Decode components
for my $subcomponent ( qw/username password db_name/ ) {
$result{$subcomponent} = _unescape_all($result{$subcomponent}) unless !(defined $result{$subcomponent});
}

$result{hostpairs} = 'localhost' unless $result{hostpairs};
$result{hostpairs} = [
$result{hostids} = 'localhost' unless $result{hostids};
$result{hostids} = [
map { lc $_ }
map { @_ = split ':', $_; _unescape_all($_[0]).":"._unescape_all($_[1]) }
map { $_ .= ':27017' unless $_ =~ /:/ ; $_ } split ',', $result{hostpairs}
map { $_ .= ':27017' unless $_ =~ /:/ ; $_ } split ',', $result{hostids}
];

if ( defined $result{options} ) {
Expand Down Expand Up @@ -195,7 +195,7 @@ sub BUILD {
MongoDB::Error->throw("URI '$self' could not be parsed");
}

for my $attr ( qw/username password db_name options hostpairs/ ) {
for my $attr ( qw/username password db_name options hostids/ ) {
my $setter = "_set_$attr";
$self->$setter( $result{$attr} ) if defined $result{$attr};
}
Expand Down
2 changes: 1 addition & 1 deletion t/sdam_spec.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub create_mock_topology {
my ($name, $string) = @_;

my $uri = MongoDB::_URI->new( uri => $string );
my $seed_count = scalar @{ $uri->hostpairs };
my $seed_count = scalar @{ $uri->hostids };

# XXX this is a hack because the direct tests are written to
# assume Single, even though this is not implied by the spec
Expand Down
2 changes: 1 addition & 1 deletion t/unit/configuration.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ subtest "host and port" => sub {
is( $mc->host, "mongodb://example.com", "host as URI is preserved" );
is( $mc->port, 99, "port changed" );
is( $mc->_uri->uri, $mc->host, "uri matches host" );
is_deeply( $mc->_uri->hostpairs, ["example.com:27017"],
is_deeply( $mc->_uri->hostids, ["example.com:27017"],
"host pairs ignores changed port" );
};

Expand Down
54 changes: 27 additions & 27 deletions t/unit/uri.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use Test::Fatal;
use MongoDB::_URI;

subtest "localhost" => sub {
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

my $uri = MongoDB::_URI->new( uri => 'mongodb://localhost');
is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);

$uri = MongoDB::_URI->new( uri => 'mongodb://localhost,');
is_deeply($uri->hostpairs, \@hostpairs, "trailing comma");
is_deeply($uri->hostids, \@hostids, "trailing comma");
};

subtest "db_name" => sub {
Expand All @@ -54,9 +54,9 @@ subtest "db_name" => sub {
subtest "localhost with username/password" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://fred:foobar@localhost');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
is($uri->username, 'fred');
is($uri->password, 'foobar');
};
Expand All @@ -65,19 +65,19 @@ subtest "localhost with username/password" => sub {
subtest "localhost with username only" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://fred@localhost');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
is($uri->username, 'fred');
is($uri->password, undef);
};

subtest "localhost with username/password and db" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://fred:foobar@localhost/baz');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
is($uri->username, 'fred');
is($uri->password, 'foobar');
is($uri->db_name, 'baz');
Expand All @@ -86,9 +86,9 @@ subtest "localhost with username/password and db" => sub {
subtest "localhost with username/password and db (trailing comma)" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://fred:foobar@localhost,/baz');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
is($uri->username, 'fred');
is($uri->password, 'foobar');
is($uri->db_name, 'baz');
Expand All @@ -97,9 +97,9 @@ subtest "localhost with username/password and db (trailing comma)" => sub {
subtest "localhost with username/password and db (trailing question)" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://fred:foobar@localhost/baz?');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
is($uri->username, 'fred');
is($uri->password, 'foobar');
is($uri->db_name, 'baz');
Expand All @@ -108,51 +108,51 @@ subtest "localhost with username/password and db (trailing question)" => sub {
subtest "localhost with empty extras" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://:@localhost/?');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "multiple hostnames" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://example1.com:27017,example2.com:27017');
my @hostpairs = ('example1.com:27017', 'example2.com:27017');
my @hostids = ('example1.com:27017', 'example2.com:27017');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "multiple hostnames at localhost" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://localhost,localhost:27018,localhost:27019');
my @hostpairs = ('localhost:27017', 'localhost:27018', 'localhost:27019');
my @hostids = ('localhost:27017', 'localhost:27018', 'localhost:27019');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "multiple hostnames (localhost/domain)" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://localhost,example1.com:27018,localhost:27019');
my @hostpairs = ('localhost:27017', 'example1.com:27018', 'localhost:27019');
my @hostids = ('localhost:27017', 'example1.com:27018', 'localhost:27019');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "multiple hostnames (localhost/domain)" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://localhost,example1.com:27018,localhost:27019');
my @hostpairs = ('localhost:27017', 'example1.com:27018', 'localhost:27019');
my @hostids = ('localhost:27017', 'example1.com:27018', 'localhost:27019');

is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "percent encoded username and password" => sub {

my $uri = MongoDB::_URI->new( uri => 'mongodb://dog%3Adogston:p%40ssword@localhost');
my @hostpairs = ('localhost:27017');
my @hostids = ('localhost:27017');

is($uri->username, 'dog:dogston');
is($uri->password, 'p@ssword');
is_deeply($uri->hostpairs, \@hostpairs);
is_deeply($uri->hostids, \@hostids);
};

subtest "empty username and password" => sub {
Expand All @@ -166,8 +166,8 @@ subtest "case normalization" => sub {
my $uri;

$uri = MongoDB::_URI->new( uri => 'mongodb://eXaMpLe1.cOm:27017,eXAMPLe2.com:27017');
my @hostpairs = ('example1.com:27017', 'example2.com:27017');
is_deeply($uri->hostpairs, \@hostpairs, "hostname normalized");
my @hostids = ('example1.com:27017', 'example2.com:27017');
is_deeply($uri->hostids, \@hostids, "hostname normalized");

$uri = MongoDB::_URI->new( uri => 'mongodb://localhost/?ReAdPrEfErEnCe=Primary&wTimeoutMS=1000' );
is( $uri->options->{readpreference}, 'Primary', "readPreference key normalized" );
Expand Down

0 comments on commit a4c9a59

Please sign in to comment.