Permalink
Browse files

Allow a prefix on table id, and a multi-component table-name prefix

  • Loading branch information...
1 parent 2fbd00f commit 09c6344fde3695846fa4449a24ec0f88ec227e6d @stuhood stuhood committed Apr 3, 2012
Showing with 27 additions and 1 deletion.
  1. +1 −1 lib/gizzard/thrift.rb
  2. +26 −0 test/nameserver_spec.rb
View
2 lib/gizzard/thrift.rb
@@ -32,7 +32,7 @@ def <=>(o)
alias_method :to_unix, :inspect
def self.parse(string)
- if groups = string.match(/(.*)\/([^_]+_\d+_\d{3,}.*)/)
+ if groups = string.match(/(.*)\/(.*\d+_\d{3,}.*)/)
new(*groups.values_at(1, 2))
else
raise "Invalid shard id '#{string}': shard ids are composed of '<table-prefix>_<table-id>_<three-or-more-digit-id>[_<optional-suffix>]'"
View
26 test/nameserver_spec.rb
@@ -1,5 +1,31 @@
require File.expand_path('../spec_helper', __FILE__)
+describe Gizzard do
+ describe "ShardId" do
+ it "parses correctly" do
+ parse_should("localhost", "edges_backward_134_134_readonly")
+ parse_should("localhost", "edges_backward_134_134_replicating")
+ parse_should("localhost", "edges_forward_134_134_readonly")
+ parse_should("localhost", "edges_forward_134_134_replicating")
+ parse_should("localhost", "edges_n134_134")
+ parse_should("localhost", "edges_n134_134_blocked")
+ parse_should("localhost", "edges_n134_134_replicating")
+ parse_should("localhost", "edges_134_134")
+ parse_should("localhost", "edges_134_134_backward_replicating")
+ parse_should("localhost", "edges_134_134_blocked")
+ parse_should("localhost", "edges_134_134_forward_replicating")
+ parse_should("localhost", "edges_134_134_replicating")
+ parse_should("localhost", "writeonly_edges_backward_134_134")
+ parse_should("localhost", "writeonly_edges_forward_134_134")
+ end
+
+ def parse_should(hostname, table_prefix)
+ Gizzard::ShardId.parse(hostname + "/" + table_prefix).should ==
+ Gizzard::ShardId.new(hostname, table_prefix)
+ end
+ end
+end
+
describe Gizzard::Shard do
describe "parse_enumeration" do
it "parses correctly" do

0 comments on commit 09c6344

Please sign in to comment.