cassandra_test_util.go ×15

Frontier kind: Code frontier

unlabeled · c_b9db736eb3a9

105 tests · 3259 LOC · 160 files · introduces 0 tests · 84 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges84 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
528 ranges3259 lines · 160 files · Browse complete extent
All tests (intent)
105 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 84 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/tests/cassandra_test_util.go 84 introduced LOC · 15 ranges

Open complete file

50 )
51
52 > func setUpCassandraTest(t *testing.T) (CassandraTestData, func()) { cassandra_test_util.go
53 > var testData CassandraTestData
54 > testData.Cfg = NewCassandraConfig()
55 > testData.Logger = log.NewZapLogger(zaptest.NewLogger(t))
56 > SetUpCassandraDatabase(t, testData.Cfg, testData.Logger)
57 > SetUpCassandraSchema(t, testData.Cfg, testData.Logger)
58 >
59 > testData.Factory = cassandra.NewFactory(
60 > *testData.Cfg,
61 > resolver.NewNoopResolver(),
62 > testCassandraClusterName,
63 > testData.Logger,
64 > metrics.NoopMetricsHandler,
65 > serialization.NewSerializer(),
66 > )
67 >
68 > tearDown := func() {
69 > testData.Factory.Close()
70 > TearDownCassandraKeyspace(t, testData.Cfg)
71 > }
72
73 > return testData, tearDown cassandra_test_util.go
74 }
75
76 > func SetUpCassandraDatabase(t *testing.T, cfg *config.Cassandra, logger log.Logger) { cassandra_test_util.go
77 > adminCfg := *cfg
78 > // NOTE need to connect with empty name to create new database
79 > adminCfg.Keyspace = "system"
80 >
81 > session, err := commongocql.NewSession(
82 > func() (*gocql.ClusterConfig, error) {
83 > return commongocql.NewCassandraCluster(adminCfg, resolver.NewNoopResolver())
84 > },
85 logger,
86 metrics.NoopMetricsHandler,
87 )
88 > if err != nil { cassandra_test_util.go
89 t.Fatalf("unable to create Cassandra session: %v", err)
90 }
91 > defer session.Close() cassandra_test_util.go
92 >
93 > if err := cassandra.CreateCassandraKeyspace(
94 > session,
95 > cfg.Keyspace,
96 > 1,
97 > true,
98 > log.NewNoopLogger(),
99 > ); err != nil {
100 t.Fatalf("unable to create Cassandra keyspace: %v", err)
101 }
102 }
103
104 > func SetUpCassandraSchema(t *testing.T, cfg *config.Cassandra, logger log.Logger) { cassandra_test_util.go
105 > ApplySchemaUpdate(t, cfg, testCassandraExecutionSchema, logger)
106 > }
107
108 > func ApplySchemaUpdate(t *testing.T, cfg *config.Cassandra, schemaFile string, logger log.Logger) { cassandra_test_util.go
109 > session, err := commongocql.NewSession(
110 > func() (*gocql.ClusterConfig, error) {
111 > return commongocql.NewCassandraCluster(*cfg, resolver.NewNoopResolver())
112 > },
113 logger,
114 metrics.NoopMetricsHandler,
115 )
116 > if err != nil { cassandra_test_util.go
117 t.Fatal(err)
118 }
119 > defer session.Close() cassandra_test_util.go
120 >
121 > schemaPath, err := filepath.Abs(schemaFile)
122 > if err != nil {
123 t.Fatal(err)
124 }
125
126 > statements, err := p.LoadAndSplitQuery([]string{schemaPath}) cassandra_test_util.go
127 > if err != nil {
128 t.Fatal(err)
129 }
130
131 > for _, stmt := range statements { cassandra_test_util.go
132 > if err = session.Query(stmt).Exec(); err != nil {
133 logger.Error(fmt.Sprintf("Unable to execute statement from file: %s\n %s", schemaFile, stmt))
134 t.Fatal(err)
137 }
138
139 > func TearDownCassandraKeyspace(t *testing.T, cfg *config.Cassandra) { cassandra_test_util.go
140 > adminCfg := *cfg
141 > // NOTE need to connect with empty name to create new database
142 > adminCfg.Keyspace = "system"
143 >
144 > session, err := commongocql.NewSession(
145 > func() (*gocql.ClusterConfig, error) {
146 > return commongocql.NewCassandraCluster(adminCfg, resolver.NewNoopResolver())
147 > },
148 log.NewNoopLogger(),
149 metrics.NoopMetricsHandler,
150 )
151 > if err != nil { cassandra_test_util.go
152 t.Fatalf("unable to create Cassandra session: %v", err)
153 }
154 > defer session.Close() cassandra_test_util.go
155 >
156 > if err := cassandra.DropCassandraKeyspace(
157 > session,
158 > cfg.Keyspace,
159 > log.NewNoopLogger(),
160 > ); err != nil {
161 t.Fatalf("unable to drop Cassandra keyspace: %v", err)
162 }
221
222 // NewCassandraConfig returns a new Cassandra config for test
223 > func NewCassandraConfig() *config.Cassandra { cassandra_test_util.go
224 > return &config.Cassandra{
225 > User: testCassandraUser,
226 > Password: testCassandraPassword,
227 > Hosts: environment.GetCassandraAddress(),
228 > Port: environment.GetCassandraPort(),
229 > Keyspace: testCassandraDatabaseNamePrefix + shuffle.String(testCassandraDatabaseNameSuffix),
230 > ConnectTimeout: 30 * time.Second,
231 > }
232 > }