test.go ×22

Frontier kind: Code frontier

unlabeled · c_8e25bfb50a33

100 tests · 3312 LOC · 160 files · introduces 0 tests · 124 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
23 ranges124 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
538 ranges3312 lines · 160 files · Browse complete extent
All tests (intent)
100 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.

2 files ranked by introduced lines: 124 introduced LOC across 23 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/cassandra/test.go 118 introduced LOC · 22 ranges

Open complete file

57
58 // NewTestCluster returns a new cassandra test cluster
59 > func NewTestCluster(keyspace, username, password, host string, port int, schemaDir string, faultInjection *config.FaultInjection, logger log.Logger) *TestCluster { test.go
60 > var result TestCluster
61 > result.logger = logger
62 > result.keyspace = keyspace
63 > if port == 0 {
64 > port = environment.GetCassandraPort()
65 > }
66 > if schemaDir == "" {
67 > schemaDir = testSchemaDir
68 > }
69 > if host == "" {
70 > host = environment.GetCassandraAddress()
71 > }
72 > result.schemaDir = schemaDir
73 > result.cfg = config.Cassandra{
74 > User: username,
75 > Password: password,
76 > Hosts: host,
77 > Port: port,
78 > MaxConns: 2,
79 > ConnectTimeout: 30 * time.Second * debug.TimeoutMultiplier,
80 > Keyspace: keyspace,
81 > }
82 > result.faultInjection = faultInjection
83 > return &result
84 }
85
97
98 // DatabaseName from PersistenceTestCluster interface
99 > func (s *TestCluster) DatabaseName() string { test.go
100 > return s.keyspace
101 > }
102
103 // SetupTestDatabase from PersistenceTestCluster interface
104 > func (s *TestCluster) SetupTestDatabase() { test.go
105 > s.CreateSession("system")
106 > s.CreateDatabase()
107 > s.CreateSession(s.DatabaseName())
108 > schemaDir := s.schemaDir + "/"
109 >
110 > if !strings.HasPrefix(schemaDir, "/") && !strings.HasPrefix(schemaDir, "../") {
111 > temporalPackageDir := testutils.GetRepoRootDirectory()
112 > schemaDir = path.Join(temporalPackageDir, schemaDir)
113 > }
114
115 > s.LoadSchema(path.Join(schemaDir, "temporal", "schema.cql")) test.go
116 > s.loadSchemaVersion()
117 }
118
119 // TearDownTestDatabase from PersistenceTestCluster interface
120 > func (s *TestCluster) TearDownTestDatabase() { test.go
121 > s.DropDatabase()
122 > s.session.Close()
123 > }
124
125 // CreateSession from PersistenceTestCluster interface
126 func (s *TestCluster) CreateSession(
127 keyspace string,
128 > ) { test.go
129 > if s.session != nil {
130 > s.session.Close()
131 > }
132
133 > var err error test.go
134 > op := func() error {
135 > session, err := commongocql.NewSession(
136 > func() (*gocql.ClusterConfig, error) {
137 > return commongocql.NewCassandraCluster(
138 > config.Cassandra{
139 > Hosts: s.cfg.Hosts,
140 > Port: s.cfg.Port,
141 > User: s.cfg.User,
142 > Password: s.cfg.Password,
143 > Keyspace: keyspace,
144 > Consistency: &config.CassandraStoreConsistency{
145 > Default: &config.CassandraConsistencySettings{
146 > Consistency: "ONE",
147 > },
148 > },
149 > ConnectTimeout: s.cfg.ConnectTimeout,
150 > },
151 > resolver.NewNoopResolver(),
152 > )
153 > },
154 log.NewNoopLogger(),
155 metrics.NoopMetricsHandler,
156 )
157 > if err == nil { test.go
158 > s.session = session
159 > }
160 > return err
161 }
162 > err = backoff.ThrottleRetry( test.go
163 > op,
164 > backoff.NewExponentialRetryPolicy(time.Second).WithExpirationInterval(time.Minute),
165 > nil,
166 > )
167 > if err != nil {
168 s.logger.Fatal("CreateSession", tag.Error(err))
169 }
170 > s.logger.Debug("created session", tag.String("keyspace", keyspace)) test.go
171 }
172
173 // CreateDatabase from PersistenceTestCluster interface
174 > func (s *TestCluster) CreateDatabase() { test.go
175 > err := CreateCassandraKeyspace(s.session, s.DatabaseName(), 1, true, s.logger)
176 > if err != nil {
177 s.logger.Fatal("CreateCassandraKeyspace", tag.Error(err))
178 }
179 > s.logger.Info("created database", tag.String("database", s.DatabaseName())) test.go
180 }
181
182 // DropDatabase from PersistenceTestCluster interface
183 > func (s *TestCluster) DropDatabase() { test.go
184 > err := DropCassandraKeyspace(s.session, s.DatabaseName(), s.logger)
185 > if err != nil && !strings.Contains(err.Error(), "AlreadyExists") {
186 s.logger.Fatal("DropCassandraKeyspace", tag.Error(err))
187 }
188 > s.logger.Info("dropped database", tag.String("database", s.DatabaseName())) test.go
189 }
190
191 // LoadSchema from PersistenceTestCluster interface
192 > func (s *TestCluster) LoadSchema(schemaFile string) { test.go
193 > statements, err := p.LoadAndSplitQuery([]string{schemaFile})
194 > if err != nil {
195 s.logger.Fatal("LoadSchema", tag.Error(err))
196 }
197 > for _, stmt := range statements { test.go
198 > if err = s.session.Query(stmt).Exec(); err != nil {
199 s.logger.Fatal("LoadSchema", tag.Error(err))
200 }
201 }
202 > s.logger.Info("loaded schema") test.go
203 }
204
205 > func (s *TestCluster) loadSchemaVersion() { test.go
206 > s.createSchemaVersionTables()
207 > s.updateSchemaVersion(cassandraschema.Version, cassandraschema.Version)
208 > s.writeSchemaUpdateLog("0", cassandraschema.Version, "", "initial version")
209 > s.logger.Info("loaded schema version", tag.String("version", cassandraschema.Version))
210 > }
211
212 > func (s *TestCluster) createSchemaVersionTables() { test.go
213 > s.execSchemaVersionQuery(createSchemaVersionTableCQL)
214 > s.execSchemaVersionQuery(createSchemaUpdateHistoryTableCQL)
215 > }
216
217 > func (s *TestCluster) updateSchemaVersion(newVersion string, minCompatibleVersion string) { test.go
218 > now := time.Now().UTC()
219 > s.execSchemaVersionQuery(
220 > writeSchemaVersionCQL,
221 > s.keyspace, now, newVersion, minCompatibleVersion)
222 > }
223
224 > func (s *TestCluster) writeSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, description string) { test.go
225 > now := time.Now().UTC()
226 > s.execSchemaVersionQuery(
227 > writeSchemaUpdateHistoryCQL,
228 > now.Year(), int(now.Month()), now, oldVersion, newVersion, manifestMD5, description)
229 > }
230
231 > func (s *TestCluster) execSchemaVersionQuery(stmt string, args ...any) { test.go
232 > if err := s.session.Query(stmt, args...).Exec(); err != nil {
233 s.logger.Fatal("loadSchemaVersion", tag.Error(err))
234 }
go.temporal.io/server/common/persistence/persistence-tests/persistence_test_base.go 6 introduced LOC · 1 range

Open complete file

128 }
129
130 > func NewTestClusterForCassandra(options *TestBaseOptions, logger log.Logger) *cassandra.TestCluster { persistence_test_base.go
131 > if options.DBName == "" {
132 > options.DBName = GenerateRandomDBName()
133 > }
134 > testCluster := cassandra.NewTestCluster(options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.SchemaDir, options.FaultInjection, logger)
135 > return testCluster
136 }
137