-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from scylladb/replication_factor_configurable
schema: replication strategy is now supported
- Loading branch information
Showing
5 changed files
with
125 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package replication | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
) | ||
|
||
type Replication map[string]interface{} | ||
|
||
func (r *Replication) ToCQL() string { | ||
b, _ := json.Marshal(r) | ||
return strings.ReplaceAll(string(b), "\"", "'") | ||
} | ||
|
||
func NewSimpleStrategy() *Replication { | ||
return &Replication{ | ||
"class": "SimpleStrategy", | ||
"replication_factor": 1, | ||
} | ||
} | ||
|
||
func NewNetworkTopologyStrategy() *Replication { | ||
return &Replication{ | ||
"class": "NetworkTopologyStrategy", | ||
"datacenter1": 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package replication | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestToCQL(t *testing.T) { | ||
tests := map[string]struct { | ||
rs *Replication | ||
want string | ||
}{ | ||
"simple": { | ||
rs: NewSimpleStrategy(), | ||
want: "{'class':'SimpleStrategy','replication_factor':1}", | ||
}, | ||
"network": { | ||
rs: NewNetworkTopologyStrategy(), | ||
want: "{'class':'NetworkTopologyStrategy','datacenter1':1}", | ||
}, | ||
} | ||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := test.rs.ToCQL() | ||
if got != test.want { | ||
t.Fatalf("expected '%s', got '%s'", test.want, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters