Skip to content

Commit f12ef8f

Browse files
author
Bulat Shakirzyanov
committed
[RUBY-119] demonstrate using alternative require
1 parent c635165 commit f12ef8f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Feature: Namespace conflicts
2+
3+
A special require syntax can be used to avoid namespace conflicts in cases
4+
where top level `Cassandra` namespace if taken.
5+
6+
Background:
7+
Given a running cassandra cluster with schema:
8+
"""cql
9+
CREATE KEYSPACE simplex WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
10+
USE simplex;
11+
CREATE TABLE songs (
12+
id uuid PRIMARY KEY,
13+
title text,
14+
album text,
15+
artist text,
16+
tags set<text>,
17+
data blob
18+
);
19+
"""
20+
21+
@cassandra-version-specific @cassandra-version-2.0
22+
Scenario: Require the gem using an alternative method
23+
Given the following example:
24+
"""ruby
25+
require 'datastax/cassandra'
26+
27+
cluster = DataStax::Cassandra.cluster
28+
session = cluster.connect("simplex")
29+
30+
rows = session.execute("SELECT * FROM songs")
31+
32+
puts "songs contain #{rows.size} rows"
33+
34+
batch = session.batch do |b|
35+
b.add("INSERT INTO songs (id, title, album, artist, tags)
36+
VALUES (
37+
756716f7-2e54-4715-9f00-91dcbea6cf50,
38+
'La Petite Tonkinoise',
39+
'Bye Bye Blackbird',
40+
'Joséphine Baker',
41+
{'jazz', '2013'}
42+
)")
43+
b.add("INSERT INTO songs (id, title, album, artist, tags)
44+
VALUES (
45+
f6071e72-48ec-4fcb-bf3e-379c8a696488,
46+
'Die Mösch',
47+
'In Gold',
48+
'Willi Ostermann',
49+
{'kölsch', '1996', 'birds'}
50+
)")
51+
b.add("INSERT INTO songs (id, title, album, artist, tags)
52+
VALUES (
53+
fbdf82ed-0063-4796-9c7c-a3d4f47b4b25,
54+
'Memo From Turner',
55+
'Performance',
56+
'Mick Jager',
57+
{'soundtrack', '1991'}
58+
)")
59+
end
60+
61+
puts "inserting rows in a batch"
62+
63+
session.execute(batch, consistency: :all)
64+
rows = session.execute("SELECT * FROM songs")
65+
66+
puts "songs contain #{rows.size} rows"
67+
"""
68+
When it is executed
69+
Then its output should contain:
70+
"""
71+
songs contain 0 rows
72+
inserting rows in a batch
73+
songs contain 3 rows
74+
"""

0 commit comments

Comments
 (0)