Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 09c6344fde3695846fa4449a24ec0f88ec227e6d 1 parent 2fbd00f
Stu Hood authored
2  lib/gizzard/thrift.rb
@@ -32,7 +32,7 @@ def <=>(o)
32 32
     alias_method :to_unix, :inspect
33 33
 
34 34
     def self.parse(string)
35  
-      if groups = string.match(/(.*)\/([^_]+_\d+_\d{3,}.*)/)
  35
+      if groups = string.match(/(.*)\/(.*\d+_\d{3,}.*)/)
36 36
         new(*groups.values_at(1, 2))
37 37
       else
38 38
         raise "Invalid shard id '#{string}': shard ids are composed of '<table-prefix>_<table-id>_<three-or-more-digit-id>[_<optional-suffix>]'"
26  test/nameserver_spec.rb
... ...
@@ -1,5 +1,31 @@
1 1
 require File.expand_path('../spec_helper', __FILE__)
2 2
 
  3
+describe Gizzard do
  4
+  describe "ShardId" do
  5
+    it "parses correctly" do
  6
+      parse_should("localhost", "edges_backward_134_134_readonly")
  7
+      parse_should("localhost", "edges_backward_134_134_replicating")
  8
+      parse_should("localhost", "edges_forward_134_134_readonly")
  9
+      parse_should("localhost", "edges_forward_134_134_replicating")
  10
+      parse_should("localhost", "edges_n134_134")
  11
+      parse_should("localhost", "edges_n134_134_blocked")
  12
+      parse_should("localhost", "edges_n134_134_replicating")
  13
+      parse_should("localhost", "edges_134_134")
  14
+      parse_should("localhost", "edges_134_134_backward_replicating")
  15
+      parse_should("localhost", "edges_134_134_blocked")
  16
+      parse_should("localhost", "edges_134_134_forward_replicating")
  17
+      parse_should("localhost", "edges_134_134_replicating")
  18
+      parse_should("localhost", "writeonly_edges_backward_134_134")
  19
+      parse_should("localhost", "writeonly_edges_forward_134_134")
  20
+    end
  21
+
  22
+    def parse_should(hostname, table_prefix)
  23
+      Gizzard::ShardId.parse(hostname + "/" + table_prefix).should ==
  24
+        Gizzard::ShardId.new(hostname, table_prefix)
  25
+    end
  26
+  end
  27
+end
  28
+
3 29
 describe Gizzard::Shard do
4 30
   describe "parse_enumeration" do
5 31
     it "parses correctly" do

0 notes on commit 09c6344

Please sign in to comment.
Something went wrong with that request. Please try again.