diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d2044a0c0..5f0bb7400 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,9 +7,6 @@ on: pull_request: types: [ opened, synchronize, reopened ] -env: - CCM_VERSION: "6e71061146f7ae67b84ccd2b1d90d7319b640e4c" - jobs: build: name: Unit tests @@ -25,177 +22,49 @@ jobs: - run: go vet - name: Run unit tests run: go test -v -tags unit -race - integration-cassandra: - timeout-minutes: 15 - needs: - - build - name: Integration Tests + + integration-tc: + needs: build runs-on: ubuntu-latest + name: integration-tc strategy: - fail-fast: false matrix: go: [ '1.22', '1.23' ] - cassandra_version: [ '4.0.13', '4.1.6' ] + cassandra_version: [ '4.0.13', '4.1.6', '5.0.0'] auth: [ "false" ] compressor: [ "snappy" ] - tags: [ "cassandra", "integration", "ccm" ] + tags: [ "cassandra", "integration", "tc"] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - - uses: actions/cache@v2 - id: gomod-cache - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Install CCM - run: pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}" - - name: Start cassandra nodes + - name: setup run: | - VERSION=${{ matrix.cassandra_version }} - keypath="$(pwd)/testdata/pki" - conf=( - "client_encryption_options.enabled: true" - "client_encryption_options.keystore: $keypath/.keystore" - "client_encryption_options.keystore_password: cassandra" - "client_encryption_options.require_client_auth: true" - "client_encryption_options.truststore: $keypath/.truststore" - "client_encryption_options.truststore_password: cassandra" - "concurrent_reads: 2" - "concurrent_writes: 2" - "write_request_timeout_in_ms: 5000" - "read_request_timeout_in_ms: 5000" - ) - - if [[ $VERSION == 3.*.* ]]; then - conf+=( - "rpc_server_type: sync" - "rpc_min_threads: 2" - "rpc_max_threads: 2" - "enable_user_defined_functions: true" - "enable_materialized_views: true" - ) - elif [[ $VERSION == 4.0.* ]]; then - conf+=( - "enable_user_defined_functions: true" - "enable_materialized_views: true" - ) - else - conf+=( - "user_defined_functions_enabled: true" - "materialized_views_enabled: true" - ) - fi - - ccm remove test || true - - ccm create test -v $VERSION -n 3 -d --vnodes --jvm_arg="-Xmx256m -XX:NewSize=100m" - ccm updateconf "${conf[@]}" - - export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" - - ccm start --wait-for-binary-proto --verbose - ccm status - ccm node1 nodetool status - - args="-gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=3 -autowait=2000ms -compressor=${{ matrix.compressor }} -gocql.cversion=$VERSION -cluster=$(ccm liveset) ./..." - + args="-gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=3 -autowait=2000ms -compressor=${{ matrix.compressor }} -gocql.cversion=${{ matrix.cassandra_version }} ./..." echo "args=$args" >> $GITHUB_ENV - echo "JVM_EXTRA_OPTS=$JVM_EXTRA_OPTS" >> $GITHUB_ENV - - name: Integration tests - run: | - export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}" - go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }} - - name: 'Save ccm logs' - if: 'failure()' - uses: actions/upload-artifact@v3 - with: - name: ccm-cluster - path: /home/runner/.ccm/test - retention-days: 5 - integration-auth-cassandra: - timeout-minutes: 15 - needs: - - build - name: Integration Tests with auth + - name: run + run: | + go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=10m -race ${{ env.args }} + + integration-auth-tc: + needs: build runs-on: ubuntu-latest + name: integration-auth-tc strategy: - fail-fast: false matrix: go: [ '1.22', '1.23' ] - cassandra_version: [ '4.0.13' ] + cassandra_version: ['4.1.6', '5.0.0' ] compressor: [ "snappy" ] - tags: [ "integration" ] - steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - - name: Install CCM - run: pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}" - - name: Start cassandra nodes + - name: setup run: | - VERSION=${{ matrix.cassandra_version }} - keypath="$(pwd)/testdata/pki" - conf=( - "client_encryption_options.enabled: true" - "client_encryption_options.keystore: $keypath/.keystore" - "client_encryption_options.keystore_password: cassandra" - "client_encryption_options.require_client_auth: true" - "client_encryption_options.truststore: $keypath/.truststore" - "client_encryption_options.truststore_password: cassandra" - "concurrent_reads: 2" - "concurrent_writes: 2" - "write_request_timeout_in_ms: 5000" - "read_request_timeout_in_ms: 5000" - "authenticator: PasswordAuthenticator" - "authorizer: CassandraAuthorizer" - "enable_user_defined_functions: true" - ) - - if [[ $VERSION == 3.*.* ]]; then - conf+=( - "rpc_server_type: sync" - "rpc_min_threads: 2" - "rpc_max_threads: 2" - "enable_user_defined_functions: true" - "enable_materialized_views: true" - ) - elif [[ $VERSION == 4.0.* ]]; then - conf+=( - "enable_user_defined_functions: true" - "enable_materialized_views: true" - ) - else - conf+=( - "user_defined_functions_enabled: true" - "materialized_views_enabled: true" - ) - fi - - ccm remove test || true - - ccm create test -v $VERSION -n 1 -d --vnodes --jvm_arg="-Xmx256m -XX:NewSize=100m" - ccm updateconf "${conf[@]}" - - rm -rf $HOME/.ccm/test/node1/data/system_auth - - export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" - - ccm start --wait-for-binary-proto --verbose - ccm status - ccm node1 nodetool status - - args="-gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=1 -autowait=2000ms -compressor=${{ matrix.compressor }} -gocql.cversion=$VERSION -cluster=$(ccm liveset) ./..." - + args="-gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=1 -autowait=2000ms -runauth -compressor=${{ matrix.compressor }} -gocql.cversion=${{ matrix.cassandra_version }}" echo "args=$args" >> $GITHUB_ENV - echo "JVM_EXTRA_OPTS=$JVM_EXTRA_OPTS" >> $GITHUB_ENV - sleep 30s - - name: Integration tests - run: | - export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}" - go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }} + - name: run + run: | + go test -v -run=TestAuthentication -tags ""integration" gocql_debug" -timeout=15s -runauth ${{ env.args }} diff --git a/CHANGELOG.md b/CHANGELOG.md index cf02cf0b9..8d0545fa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - +- Integrated testcontainers-go as the new test runner for integration tests. ### Changed - +- Updated GitHub workflows to use `testcontainers-go` for CCM integration tests, replacing the previous CCM integration test runner. ### Fixed +- Corrected `rpc_address` to `connect_address` in the `TestDiscoverViaProxy` test case. ## [1.7.0] - 2024-09-23 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0231b063c..ef4b0942f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,6 +21,23 @@ The following is a check list of requirements that need to be satisfied in order * The merge commit passes the regression test suite on GitHub Actions * `go fmt` has been applied to the submitted code * Notable changes (i.e. new features or changed behavior, bugfixes) are appropriately documented in CHANGELOG.md, functional changes also in godoc +* Before a Pull Request or a new commit, ensure that all tests pass successfully. You can run all tests locally using the following command (this process takes approximately 15 minutes): +``` +go test -v -tags "integration cassandra tc gocql_debug" -timeout=20m -race -gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=3 -autowait=2000ms -compressor=snappy -gocql.cversion=4.0.8 ./... +``` +and +``` +go test -v -run=TestAuthentication -tags ""integration" gocql_debug" -timeout=2m -runauth -gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=1 -autowait=2000ms -runauth -compressor=snappy -gocql.cversion=4.0.8 +``` +### ℹ️ **Note:** + +> The main_test.go file serves as the entry point for integration tests. It sets up an actual Cassandra cluster, sharing resources before tests are run and cleaning them up afterward, ensuring a consistent and efficient testing environment. The cluster is created locally, so you will need Docker installed. +> +> +> The setup supports both single-node (quick setup in seconds) and multi-node Cassandra clusters (approx. 5 minutes, configurable via the `-clusterSize` flag). If you're curious to try integration tests, feel free to run them yourself. Just ensure that your tests are tagged correctly (e.g., `integration`), since `main_test.go` skips unit tests for performance reasons (no need to start a cluster for unit tests) +> +> You can find examples of running integration tests in the "Before a Pull Request" section. +> * A correctly formatted commit message, see below If there are any requirements that can't be reasonably satisfied, please state this either on the pull request or as part of discussion on the mailing list. Where appropriate, the core team may apply discretion and make an exception to these requirements. diff --git a/NOTICE b/NOTICE index f4447175c..3a2acfefb 100644 --- a/NOTICE +++ b/NOTICE @@ -182,3 +182,4 @@ Dmitry Kropachev Oliver Boyle * Jackson Fleming * Sylwia Szunejko * +Stanislav Bychkov diff --git a/cassandra_test.go b/cassandra_test.go index 797a7cf7f..30331ff5c 100644 --- a/cassandra_test.go +++ b/cassandra_test.go @@ -479,15 +479,15 @@ func TestCAS(t *testing.T) { } insertBatch := session.NewBatch(LoggedBatch) - insertBatch.Query("INSERT INTO cas_table (title, revid, last_modified) VALUES ('_foo', 2c3af400-73a4-11e5-9381-29463d90c3f0, DATEOF(NOW()))") - insertBatch.Query("INSERT INTO cas_table (title, revid, last_modified) VALUES ('_foo', 3e4ad2f1-73a4-11e5-9381-29463d90c3f0, DATEOF(NOW()))") + insertBatch.Query("INSERT INTO cas_table (title, revid, last_modified) VALUES ('_foo', 2c3af400-73a4-11e5-9381-29463d90c3f0, toTimestamp(NOW()))") + insertBatch.Query("INSERT INTO cas_table (title, revid, last_modified) VALUES ('_foo', 3e4ad2f1-73a4-11e5-9381-29463d90c3f0, toTimestamp(NOW()))") if err := session.ExecuteBatch(insertBatch); err != nil { t.Fatal("insert:", err) } failBatch = session.NewBatch(LoggedBatch) - failBatch.Query("UPDATE cas_table SET last_modified = DATEOF(NOW()) WHERE title='_foo' AND revid=2c3af400-73a4-11e5-9381-29463d90c3f0 IF last_modified=DATEOF(NOW());") - failBatch.Query("UPDATE cas_table SET last_modified = DATEOF(NOW()) WHERE title='_foo' AND revid=3e4ad2f1-73a4-11e5-9381-29463d90c3f0 IF last_modified=DATEOF(NOW());") + failBatch.Query("UPDATE cas_table SET last_modified = toTimestamp(NOW()) WHERE title='_foo' AND revid=2c3af400-73a4-11e5-9381-29463d90c3f0 IF last_modified=toTimestamp(NOW());") + failBatch.Query("UPDATE cas_table SET last_modified = toTimestamp(NOW()) WHERE title='_foo' AND revid=3e4ad2f1-73a4-11e5-9381-29463d90c3f0 IF last_modified=toTimestamp(NOW());") if applied, iter, err := session.ExecuteBatchCAS(failBatch, &titleCAS, &revidCAS, &modifiedCAS); err != nil { t.Fatal("insert:", err) } else if applied { @@ -628,7 +628,6 @@ func TestBatch(t *testing.T) { } func TestUnpreparedBatch(t *testing.T) { - t.Skip("FLAKE skipping") session := createSession(t) defer session.Close() @@ -3029,14 +3028,12 @@ func TestDiscoverViaProxy(t *testing.T) { session := createSessionFromCluster(cluster, t) defer session.Close() - // we shouldnt need this but to be safe - time.Sleep(1 * time.Second) - session.pool.mu.RLock() + for _, host := range clusterHosts { found := false for _, hi := range session.pool.hostConnPools { - if hi.host.ConnectAddress().String() == host { + if hi.host.RPCAddress().String() == host { found = true break } diff --git a/control_ccm_test.go b/control_tc_test.go similarity index 75% rename from control_ccm_test.go rename to control_tc_test.go index 426a59aef..53a0c3644 100644 --- a/control_ccm_test.go +++ b/control_tc_test.go @@ -1,5 +1,5 @@ -//go:build ccm -// +build ccm +//go:build tc +// +build tc /* * Licensed to the Apache Software Foundation (ASF) under one @@ -28,17 +28,16 @@ package gocql import ( + "context" "fmt" "sync" "testing" "time" - - "github.com/gocql/gocql/internal/ccm" ) type TestHostFilter struct { mu sync.Mutex - allowedHosts map[string]ccm.Host + allowedHosts map[string]*tcNode } func (f *TestHostFilter) Accept(h *HostInfo) bool { @@ -48,37 +47,27 @@ func (f *TestHostFilter) Accept(h *HostInfo) bool { return ok } -func (f *TestHostFilter) SetAllowedHosts(hosts map[string]ccm.Host) { +func (f *TestHostFilter) SetAllowedHosts(hosts map[string]*tcNode) { f.mu.Lock() defer f.mu.Unlock() f.allowedHosts = hosts } func TestControlConn_ReconnectRefreshesRing(t *testing.T) { - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - allCcmHosts, err := ccm.Status() - if err != nil { - t.Fatal(err) - } + ctx := context.Background() - if len(allCcmHosts) < 2 { + if len(cassNodes) < 2 { t.Skip("this test requires at least 2 nodes") } - allAllowedHosts := map[string]ccm.Host{} - var firstNode *ccm.Host - for _, node := range allCcmHosts { - if firstNode == nil { - firstNode = &node - } + allAllowedHosts := map[string]*tcNode{} + for _, node := range cassNodes { allAllowedHosts[node.Addr] = node } - allowedHosts := map[string]ccm.Host{ - firstNode.Addr: *firstNode, + firstNode := cassNodes["node1"] + allowedHosts := map[string]*tcNode{ + firstNode.Addr: firstNode, } testFilter := &TestHostFilter{allowedHosts: allowedHosts} @@ -99,9 +88,9 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) { ccHost := controlConnection.host var ccHostName string - for _, node := range allCcmHosts { + for name, node := range cassNodes { if node.Addr == ccHost.ConnectAddress().String() { - ccHostName = node.Name + ccHostName = name break } } @@ -110,25 +99,15 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) { t.Fatal("could not find name of control host") } - if err := ccm.NodeDown(ccHostName); err != nil { + if err := cassNodes[ccHostName].TC.Stop(ctx, nil); err != nil { t.Fatal() } - defer func() { - ccmStatus, err := ccm.Status() - if err != nil { - t.Logf("could not bring nodes back up after test: %v", err) - return - } - for _, node := range ccmStatus { - if node.State == ccm.NodeStateDown { - err = ccm.NodeUp(node.Name) - if err != nil { - t.Logf("could not bring node %v back up after test: %v", node.Name, err) - } - } + defer func(ctx context.Context) { + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't restore a cluster : %v", err) } - }() + }(ctx) assertNodeDown := func() error { hosts := session.ring.currentHosts() @@ -159,19 +138,19 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) { } if assertErr != nil { - t.Fatal(err) + t.Fatal(assertErr) } testFilter.SetAllowedHosts(allAllowedHosts) - if err = ccm.NodeUp(ccHostName); err != nil { + if err := restoreCluster(ctx); err != nil { t.Fatal(err) } assertNodeUp := func() error { hosts := session.ring.currentHosts() - if len(hosts) != len(allCcmHosts) { - return fmt.Errorf("expected %v hosts in ring but there were %v", len(allCcmHosts), len(hosts)) + if len(hosts) != len(cassNodes) { + return fmt.Errorf("expected %v hosts in ring but there were %v", len(ccHostName), len(hosts)) } for _, host := range hosts { if !host.IsUp() { @@ -181,8 +160,8 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) { session.pool.mu.RLock() poolsLen := len(session.pool.hostConnPools) session.pool.mu.RUnlock() - if poolsLen != len(allCcmHosts) { - return fmt.Errorf("expected %v connection pool but there were %v", len(allCcmHosts), poolsLen) + if poolsLen != len(cassNodes) { + return fmt.Errorf("expected %v connection pool but there were %v", len(ccHostName), poolsLen) } return nil } @@ -196,6 +175,6 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) { } if assertErr != nil { - t.Fatal(err) + t.Fatal(assertErr) } } diff --git a/events_ccm_test.go b/events_ccm_test.go deleted file mode 100644 index a105985bc..000000000 --- a/events_ccm_test.go +++ /dev/null @@ -1,322 +0,0 @@ -//go:build (ccm && ignore) || ignore -// +build ccm,ignore ignore - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 - * Copyright (c) 2016, The Gocql authors, - * provided under the BSD-3-Clause License. - * See the NOTICE file distributed with this work for additional information. - */ - -package gocql - -import ( - "log" - "testing" - "time" - - "github.com/gocql/gocql/internal/ccm" -) - -func TestEventDiscovery(t *testing.T) { - t.Skip("FLAKE skipping") - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - session := createSession(t) - defer session.Close() - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - t.Logf("status=%+v\n", status) - - session.pool.mu.RLock() - poolHosts := session.pool.hostConnPools // TODO: replace with session.ring - t.Logf("poolhosts=%+v\n", poolHosts) - // check we discovered all the nodes in the ring - for _, host := range status { - if _, ok := poolHosts[host.Addr]; !ok { - t.Errorf("did not discover %q", host.Addr) - } - } - session.pool.mu.RUnlock() - if t.Failed() { - t.FailNow() - } -} - -func TestEventNodeDownControl(t *testing.T) { - t.Skip("FLAKE skipping") - const targetNode = "node1" - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - - cluster := createCluster() - cluster.Hosts = []string{status[targetNode].Addr} - session := createSessionFromCluster(cluster, t) - defer session.Close() - - t.Log("marking " + targetNode + " as down") - if err := ccm.NodeDown(targetNode); err != nil { - t.Fatal(err) - } - - t.Logf("status=%+v\n", status) - t.Logf("marking node %q down: %v\n", targetNode, status[targetNode]) - - time.Sleep(5 * time.Second) - - session.pool.mu.RLock() - - poolHosts := session.pool.hostConnPools - node := status[targetNode] - t.Logf("poolhosts=%+v\n", poolHosts) - - if _, ok := poolHosts[node.Addr]; ok { - session.pool.mu.RUnlock() - t.Fatal("node not removed after remove event") - } - session.pool.mu.RUnlock() - - host := session.ring.getHost(node.Addr) - if host == nil { - t.Fatal("node not in metadata ring") - } else if host.IsUp() { - t.Fatalf("not not marked as down after event in metadata: %v", host) - } -} - -func TestEventNodeDown(t *testing.T) { - t.Skip("FLAKE skipping") - const targetNode = "node3" - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - session := createSession(t) - defer session.Close() - - if err := ccm.NodeDown(targetNode); err != nil { - t.Fatal(err) - } - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - t.Logf("status=%+v\n", status) - t.Logf("marking node %q down: %v\n", targetNode, status[targetNode]) - - time.Sleep(5 * time.Second) - - session.pool.mu.RLock() - defer session.pool.mu.RUnlock() - - poolHosts := session.pool.hostConnPools - node := status[targetNode] - t.Logf("poolhosts=%+v\n", poolHosts) - - if _, ok := poolHosts[node.Addr]; ok { - t.Fatal("node not removed after remove event") - } - - host := session.ring.getHost(node.Addr) - if host == nil { - t.Fatal("node not in metadata ring") - } else if host.IsUp() { - t.Fatalf("not not marked as down after event in metadata: %v", host) - } -} - -func TestEventNodeUp(t *testing.T) { - t.Skip("FLAKE skipping") - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - log.Printf("status=%+v\n", status) - - session := createSession(t) - defer session.Close() - - const targetNode = "node2" - node := status[targetNode] - - _, ok := session.pool.getPool(node.Addr) - if !ok { - session.pool.mu.RLock() - t.Errorf("target pool not in connection pool: addr=%q pools=%v", status[targetNode].Addr, session.pool.hostConnPools) - session.pool.mu.RUnlock() - t.FailNow() - } - - if err := ccm.NodeDown(targetNode); err != nil { - t.Fatal(err) - } - - time.Sleep(5 * time.Second) - - _, ok = session.pool.getPool(node.Addr) - if ok { - t.Fatal("node not removed after remove event") - } - - if err := ccm.NodeUp(targetNode); err != nil { - t.Fatal(err) - } - - // cassandra < 2.2 needs 10 seconds to start up the binary service - time.Sleep(15 * time.Second) - - _, ok = session.pool.getPool(node.Addr) - if !ok { - t.Fatal("node not added after node added event") - } - - host := session.ring.getHost(node.Addr) - if host == nil { - t.Fatal("node not in metadata ring") - } else if !host.IsUp() { - t.Fatalf("not not marked as UP after event in metadata: addr=%q host=%p: %v", node.Addr, host, host) - } -} - -func TestEventFilter(t *testing.T) { - t.Skip("FLAKE skipping") - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - log.Printf("status=%+v\n", status) - - cluster := createCluster() - cluster.HostFilter = WhiteListHostFilter(status["node1"].Addr) - session := createSessionFromCluster(cluster, t) - defer session.Close() - - if _, ok := session.pool.getPool(status["node1"].Addr); !ok { - t.Errorf("should have %v in pool but dont", "node1") - } - - for _, host := range [...]string{"node2", "node3"} { - _, ok := session.pool.getPool(status[host].Addr) - if ok { - t.Errorf("should not have %v in pool", host) - } - } - - if t.Failed() { - t.FailNow() - } - - if err := ccm.NodeDown("node2"); err != nil { - t.Fatal(err) - } - - time.Sleep(5 * time.Second) - - if err := ccm.NodeUp("node2"); err != nil { - t.Fatal(err) - } - - time.Sleep(15 * time.Second) - for _, host := range [...]string{"node2", "node3"} { - _, ok := session.pool.getPool(status[host].Addr) - if ok { - t.Errorf("should not have %v in pool", host) - } - } - - if t.Failed() { - t.FailNow() - } - -} - -func TestEventDownQueryable(t *testing.T) { - t.Skip("FLAKE skipping") - if err := ccm.AllUp(); err != nil { - t.Fatal(err) - } - - status, err := ccm.Status() - if err != nil { - t.Fatal(err) - } - log.Printf("status=%+v\n", status) - - const targetNode = "node1" - - addr := status[targetNode].Addr - - cluster := createCluster() - cluster.Hosts = []string{addr} - cluster.HostFilter = WhiteListHostFilter(addr) - session := createSessionFromCluster(cluster, t) - defer session.Close() - - if pool, ok := session.pool.getPool(addr); !ok { - t.Fatalf("should have %v in pool but dont", addr) - } else if !pool.host.IsUp() { - t.Fatalf("host is not up %v", pool.host) - } - - if err := ccm.NodeDown(targetNode); err != nil { - t.Fatal(err) - } - - time.Sleep(5 * time.Second) - - if err := ccm.NodeUp(targetNode); err != nil { - t.Fatal(err) - } - - time.Sleep(15 * time.Second) - - if pool, ok := session.pool.getPool(addr); !ok { - t.Fatalf("should have %v in pool but dont", addr) - } else if !pool.host.IsUp() { - t.Fatalf("host is not up %v", pool.host) - } - - var rows int - if err := session.Query("SELECT COUNT(*) FROM system.local").Scan(&rows); err != nil { - t.Fatal(err) - } else if rows != 1 { - t.Fatalf("expected to get 1 row got %d", rows) - } -} diff --git a/events_tc_test.go b/events_tc_test.go new file mode 100644 index 000000000..b1f56182e --- /dev/null +++ b/events_tc_test.go @@ -0,0 +1,240 @@ +//go:build tc +// +build tc + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 + * Copyright (c) 2016, The Gocql authors, + * provided under the BSD-3-Clause License. + * See the NOTICE file distributed with this work for additional information. + */ + +package gocql + +import ( + "context" + "testing" + "time" +) + +func TestEventDiscovery(t *testing.T) { + session := createSession(t) + defer session.Close() + + // check we discovered all the nodes in the ring + for _, node := range cassNodes { + host := session.ring.getHost(node.HostID) + if host == nil { + t.Errorf("did not discover %q", node.Addr) + } + if t.Failed() { + t.FailNow() + } + } +} + +func TestEventNodeDownControl(t *testing.T) { + ctx := context.Background() + const targetNode = "node1" + + node := cassNodes[targetNode] + cluster := createCluster() + cluster.Hosts = []string{node.Addr} + session := createSessionFromCluster(cluster, t) + defer session.Close() + + t.Logf("marking node %q down \n", targetNode) + if err := node.TC.Stop(ctx, nil); err != nil { + t.Fatal(err) + } + defer func(ctx context.Context) { + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't restore a cluster : %v", err) + } + }(ctx) + + if _, ok := getPool(session.pool, node.HostID); ok { + t.Fatal("node not removed after remove event") + } + + host := session.ring.getHost(node.HostID) + if host == nil { + t.Fatal("node not in metadata ring") + } else if host.IsUp() { + t.Fatalf("not not marked as down after event in metadata: %v", host) + } +} + +func TestEventNodeDown(t *testing.T) { + ctx := context.Background() + + const targetNode = "node3" + node := cassNodes[targetNode] + + session := createSession(t) + defer session.Close() + + if err := node.TC.Stop(ctx, nil); err != nil { + t.Fatal(err) + } + defer func(ctx context.Context) { + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't restore a cluster : %v", err) + } + }(ctx) + + if _, ok := getPool(session.pool, node.HostID); ok { + t.Errorf("node not removed after remove event") + } + + host := session.ring.getHost(node.HostID) + if host == nil { + t.Fatal("node not in metadata ring") + } else if host.IsUp() { + t.Fatalf("not not marked as down after event in metadata: %v", host) + } +} + +func TestEventNodeUp(t *testing.T) { + ctx := context.Background() + + session := createSession(t) + defer session.Close() + + const targetNode = "node2" + node := cassNodes[targetNode] + + if _, ok := getPool(session.pool, node.HostID); !ok { + t.Errorf("target pool not in connection pool: addr=%q pools=%v", node.Addr, session.pool.hostConnPools) + t.FailNow() + } + + if err := node.TC.Stop(ctx, nil); err != nil { + t.Fatal(err) + } + + if _, ok := getPool(session.pool, node.HostID); ok { + t.Fatal("node not removed after remove event") + } + + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't restore a cluster : %v", err) + } + + // cassandra < 2.2 needs 10 seconds to start up the binary service + time.Sleep(15 * time.Second) + + if _, ok := getPool(session.pool, node.HostID); !ok { + t.Fatal("node not added after node added event") + } + + host := session.ring.getHost(node.HostID) + if host == nil { + t.Fatal("node not in metadata ring") + } else if !host.IsUp() { + t.Fatalf("not not marked as UP after event in metadata: addr=%q host=%p: %v", node.Addr, host, host) + } +} + +func TestEventFilter(t *testing.T) { + ctx := context.Background() + + cluster := createCluster() + + whiteListedNodeName := "node1" + whiteListedNode := cassNodes[whiteListedNodeName] + cluster.HostFilter = WhiteListHostFilter(whiteListedNode.Addr) + + session := createSessionFromCluster(cluster, t) + defer session.Close() + + if _, ok := getPool(session.pool, whiteListedNode.HostID); !ok { + t.Errorf("should have %v in pool but dont", whiteListedNodeName) + } + + for _, node := range [...]string{"node2", "node3"} { + if _, ok := getPool(session.pool, cassNodes[node].HostID); ok { + t.Errorf("should not have %v in pool", node) + } + } + + if t.Failed() { + t.FailNow() + } + + shutdownNode := cassNodes["node2"] + + if err := shutdownNode.TC.Stop(ctx, nil); err != nil { + t.Fatal(err) + } + + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't restore a cluster : %v", err) + } + + for _, node := range [...]string{"node2", "node3"} { + _, ok := getPool(session.pool, cassNodes[node].HostID) + if ok { + t.Errorf("should not have %v in pool", node) + } + } + + if t.Failed() { + t.FailNow() + } +} + +func TestEventDownQueryable(t *testing.T) { + ctx := context.Background() + + targetNode := cassNodes["node1"] + + cluster := createCluster() + cluster.Hosts = []string{targetNode.Addr} + cluster.HostFilter = WhiteListHostFilter(targetNode.Addr) + session := createSessionFromCluster(cluster, t) + defer session.Close() + + if pool, ok := getPool(session.pool, targetNode.HostID); !ok { + t.Fatalf("should have %v in pool but dont", targetNode.Addr) + } else if !pool.host.IsUp() { + t.Fatalf("host is not up %v", pool.host) + } + + if err := targetNode.TC.Stop(ctx, nil); err != nil { + t.Fatal(err) + } + + if err := restoreCluster(ctx); err != nil { + t.Fatalf("couldn't preserve a cluster : %v", err) + } + + if pool, ok := getPool(session.pool, targetNode.HostID); !ok { + t.Fatalf("should have %v in pool but dont", targetNode.Addr) + } else if !pool.host.IsUp() { + t.Fatalf("host is not up %v", pool.host) + } + + var rows int + if err := session.Query("SELECT COUNT(*) FROM system.local").Scan(&rows); err != nil { + t.Fatal(err) + } else if rows != 1 { + t.Fatalf("expected to get 1 row got %d", rows) + } +} diff --git a/go.mod b/go.mod index 0aea881ec..ff24cd732 100644 --- a/go.mod +++ b/go.mod @@ -17,14 +17,60 @@ // module github.com/gocql/gocql +go 1.23 + require ( - github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect - github.com/golang/snappy v0.0.3 + github.com/golang/snappy v0.0.4 github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed - github.com/kr/pretty v0.1.0 // indirect - github.com/stretchr/testify v1.3.0 // indirect + github.com/testcontainers/testcontainers-go v0.33.0 gopkg.in/inf.v0 v0.9.1 ) -go 1.13 +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/bitly/go-hostpool v0.1.0 // indirect + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/containerd/containerd v1.7.18 // indirect + github.com/containerd/log v0.1.0 // indirect + github.com/containerd/platforms v0.2.1 // indirect + github.com/cpuguy83/dockercfg v0.3.1 // indirect + github.com/distribution/reference v0.6.0 // indirect + github.com/docker/docker v27.1.1+incompatible // indirect + github.com/docker/go-connections v0.5.0 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/klauspost/compress v1.17.4 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/patternmatcher v0.6.0 // indirect + github.com/moby/sys/sequential v0.5.0 // indirect + github.com/moby/sys/user v0.1.0 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shirou/gopsutil/v3 v3.23.12 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/sys v0.21.0 // indirect +) diff --git a/go.sum b/go.sum index 2e3892bcb..9f0781765 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,201 @@ -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/bitly/go-hostpool v0.1.0 h1:XKmsF6k5el6xHG3WPJ8U0Ku/ye7njX7W81Ng7O2ioR0= +github.com/bitly/go-hostpool v0.1.0/go.mod h1:4gOCgp6+NZnVqlKyZ/iBZFTAJKembaVENUpMkpg42fw= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao= +github.com/containerd/containerd v1.7.18/go.mod h1:IYEk9/IO6wAPUz2bCMVUbsfXjzw5UNP5fLz4PsUygQ4= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= +github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= +github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY= +github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= +github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= +github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= +github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= +github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= +github.com/shirou/gopsutil/v3 v3.23.12/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/testcontainers/testcontainers-go v0.33.0 h1:zJS9PfXYT5O0ZFXM2xxXfk4J5UMw/kRiISng037Gxdw= +github.com/testcontainers/testcontainers-go v0.33.0/go.mod h1:W80YpTa8D5C3Yy16icheD01UTDu+LmXIA2Keo+jWtT8= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= +go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= +golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 h1:vlzZttNJGVqTsRFU9AmdnrcO1Znh8Ew9kCD//yjigk0= +google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI= +google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/install_test_deps.sh b/install_test_deps.sh deleted file mode 100755 index 048f768bc..000000000 --- a/install_test_deps.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -set -x - -# This is not supposed to be an error-prone script; just a convenience. - -# Install CCM -pip install -i https://pypi.org/simple --user cql PyYAML six psutil -git clone https://github.com/pcmanus/ccm.git -pushd ccm -./setup.py install --user -popd diff --git a/integration.sh b/integration.sh deleted file mode 100755 index b61f0ff48..000000000 --- a/integration.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -set -eux - -function run_tests() { - local clusterSize=3 - local version=$1 - local auth=$2 - local compressor=$3 - - if [ "$auth" = true ]; then - clusterSize=1 - fi - - local keypath="$(pwd)/testdata/pki" - - local conf=( - "client_encryption_options.enabled: true" - "client_encryption_options.keystore: $keypath/.keystore" - "client_encryption_options.keystore_password: cassandra" - "client_encryption_options.require_client_auth: true" - "client_encryption_options.truststore: $keypath/.truststore" - "client_encryption_options.truststore_password: cassandra" - "concurrent_reads: 2" - "concurrent_writes: 2" - "rpc_server_type: sync" - "rpc_min_threads: 2" - "rpc_max_threads: 2" - "write_request_timeout_in_ms: 5000" - "read_request_timeout_in_ms: 5000" - ) - - ccm remove test || true - - ccm create test -v $version -n $clusterSize -d --vnodes --jvm_arg="-Xmx256m -XX:NewSize=100m" - ccm updateconf "${conf[@]}" - - if [ "$auth" = true ] - then - ccm updateconf 'authenticator: PasswordAuthenticator' 'authorizer: CassandraAuthorizer' - rm -rf $HOME/.ccm/test/node1/data/system_auth - fi - - local proto=2 - if [[ $version == 1.2.* ]]; then - proto=1 - elif [[ $version == 2.0.* ]]; then - proto=2 - elif [[ $version == 2.1.* ]]; then - proto=3 - elif [[ $version == 2.2.* || $version == 3.0.* ]]; then - proto=4 - ccm updateconf 'enable_user_defined_functions: true' - export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" - elif [[ $version == 3.*.* ]]; then - proto=5 - ccm updateconf 'enable_user_defined_functions: true' - export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" - fi - - sleep 1s - - ccm list - ccm start --wait-for-binary-proto - ccm status - ccm node1 nodetool status - - local args="-gocql.timeout=60s -runssl -proto=$proto -rf=3 -clusterSize=$clusterSize -autowait=2000ms -compressor=$compressor -gocql.cversion=$version -cluster=$(ccm liveset) ./..." - - go test -v -tags unit -race - - if [ "$auth" = true ] - then - sleep 30s - go test -run=TestAuthentication -tags "integration gocql_debug" -timeout=15s -runauth $args - else - sleep 1s - go test -tags "cassandra gocql_debug" -timeout=5m -race $args - - ccm clear - ccm start --wait-for-binary-proto - sleep 1s - - go test -tags "integration gocql_debug" -timeout=5m -race $args - - ccm clear - ccm start --wait-for-binary-proto - sleep 1s - - go test -tags "ccm gocql_debug" -timeout=5m -race $args - fi - - ccm remove -} - -run_tests $1 $2 $3 diff --git a/integration_test.go b/integration_test.go index 3622dfbd6..8c1466bdf 100644 --- a/integration_test.go +++ b/integration_test.go @@ -272,3 +272,28 @@ func TestUDF(t *testing.T) { t.Fatal(err) } } + +func TestAllNodesConnected(t *testing.T) { + cluster := createCluster() + cluster.PoolConfig.HostSelectionPolicy = RoundRobinHostPolicy() + + session := createSessionFromCluster(cluster, t) + defer session.Close() + + ids := make(map[string]bool) + + // Loop to query system.local multiple times. If there is a cluster with more than 10 nodes add to the loop more iterations + for i := 0; i < 10; i++ { + var hostID string + err := session.Query("SELECT host_id FROM system.local").Scan(&hostID) + if err != nil { + t.Fatal(err) + } + + ids[hostID] = true + } + + if *clusterSize != len(ids) { + t.Fatalf("Expected to connect to %d unique nodes", *clusterSize) + } +} diff --git a/internal/ccm/ccm.go b/internal/ccm/ccm.go deleted file mode 100644 index 55b540158..000000000 --- a/internal/ccm/ccm.go +++ /dev/null @@ -1,202 +0,0 @@ -//go:build ccm -// +build ccm - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 - * Copyright (c) 2016, The Gocql authors, - * provided under the BSD-3-Clause License. - * See the NOTICE file distributed with this work for additional information. - */ - -package ccm - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "os/exec" - "runtime" - "strings" -) - -func execCmd(args ...string) (*bytes.Buffer, error) { - execName := "ccm" - if runtime.GOOS == "windows" { - args = append([]string{"/c", execName}, args...) - execName = "cmd.exe" - } - cmd := exec.Command(execName, args...) - stdout := &bytes.Buffer{} - cmd.Stdout = stdout - cmd.Stderr = &bytes.Buffer{} - if err := cmd.Run(); err != nil { - return nil, errors.New(cmd.Stderr.(*bytes.Buffer).String()) - } - - return stdout, nil -} - -func AllUp() error { - status, err := Status() - if err != nil { - return err - } - - for _, host := range status { - if !host.State.IsUp() { - if err := NodeUp(host.Name); err != nil { - return err - } - } - } - - return nil -} - -func NodeUp(node string) error { - args := []string{node, "start", "--wait-for-binary-proto"} - if runtime.GOOS == "windows" { - args = append(args, "--quiet-windows") - } - _, err := execCmd(args...) - return err -} - -func NodeDown(node string) error { - _, err := execCmd(node, "stop") - return err -} - -type Host struct { - State NodeState - Addr string - Name string -} - -type NodeState int - -func (n NodeState) String() string { - if n == NodeStateUp { - return "UP" - } else if n == NodeStateDown { - return "DOWN" - } else { - return fmt.Sprintf("UNKNOWN_STATE_%d", n) - } -} - -func (n NodeState) IsUp() bool { - return n == NodeStateUp -} - -const ( - NodeStateUp NodeState = iota - NodeStateDown -) - -func Status() (map[string]Host, error) { - // TODO: parse into struct to manipulate - out, err := execCmd("status", "-v") - if err != nil { - return nil, err - } - - const ( - stateCluster = iota - stateCommas - stateNode - stateOption - ) - - nodes := make(map[string]Host) - // didnt really want to write a full state machine parser - state := stateCluster - sc := bufio.NewScanner(out) - - var host Host - - for sc.Scan() { - switch state { - case stateCluster: - text := sc.Text() - if !strings.HasPrefix(text, "Cluster:") { - return nil, fmt.Errorf("expected 'Cluster:' got %q", text) - } - state = stateCommas - case stateCommas: - text := sc.Text() - if !strings.HasPrefix(text, "-") { - return nil, fmt.Errorf("expected commas got %q", text) - } - state = stateNode - case stateNode: - // assume nodes start with node - text := sc.Text() - if !strings.HasPrefix(text, "node") { - return nil, fmt.Errorf("expected 'node' got %q", text) - } - line := strings.Split(text, ":") - host.Name = line[0] - - nodeState := strings.TrimSpace(line[1]) - switch nodeState { - case "UP": - host.State = NodeStateUp - case "DOWN": - host.State = NodeStateDown - default: - return nil, fmt.Errorf("unknown node state from ccm: %q", nodeState) - } - - state = stateOption - case stateOption: - text := sc.Text() - if text == "" { - state = stateNode - nodes[host.Name] = host - host = Host{} - continue - } - - line := strings.Split(strings.TrimSpace(text), "=") - k, v := line[0], line[1] - if k == "binary" { - // could check errors - // ('127.0.0.1', 9042) - v = v[2:] // ('' - if i := strings.IndexByte(v, '\''); i < 0 { - return nil, fmt.Errorf("invalid binary v=%q", v) - } else { - host.Addr = v[:i] - // dont need port - } - } - default: - return nil, fmt.Errorf("unexpected state: %q", state) - } - } - - if err := sc.Err(); err != nil { - return nil, fmt.Errorf("unable to parse ccm status: %v", err) - } - - return nodes, nil -} diff --git a/internal/ccm/ccm_test.go b/internal/ccm/ccm_test.go deleted file mode 100644 index b8fa9efce..000000000 --- a/internal/ccm/ccm_test.go +++ /dev/null @@ -1,73 +0,0 @@ -//go:build ccm -// +build ccm - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 - * Copyright (c) 2016, The Gocql authors, - * provided under the BSD-3-Clause License. - * See the NOTICE file distributed with this work for additional information. - */ - -package ccm - -import ( - "testing" -) - -func TestCCM(t *testing.T) { - if err := AllUp(); err != nil { - t.Fatal(err) - } - - status, err := Status() - if err != nil { - t.Fatal(err) - } - - if host, ok := status["node1"]; !ok { - t.Fatal("node1 not in status list") - } else if !host.State.IsUp() { - t.Fatal("node1 is not up") - } - - NodeDown("node1") - status, err = Status() - if err != nil { - t.Fatal(err) - } - - if host, ok := status["node1"]; !ok { - t.Fatal("node1 not in status list") - } else if host.State.IsUp() { - t.Fatal("node1 is not down") - } - - NodeUp("node1") - status, err = Status() - if err != nil { - t.Fatal(err) - } - - if host, ok := status["node1"]; !ok { - t.Fatal("node1 not in status list") - } else if !host.State.IsUp() { - t.Fatal("node1 is not up") - } -} diff --git a/main_test.go b/main_test.go new file mode 100644 index 000000000..9f65af9c6 --- /dev/null +++ b/main_test.go @@ -0,0 +1,235 @@ +//go:build cassandra || integration || tc +// +build cassandra integration tc + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 + * Copyright (c) 2016, The Gocql authors, + * provided under the BSD-3-Clause License. + * See the NOTICE file distributed with this work for additional information. + */ + +package gocql + +import ( + "context" + "flag" + "fmt" + "log" + "os" + "strconv" + "testing" + "time" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/network" + "github.com/testcontainers/testcontainers-go/wait" +) + +type tcNode struct { + TC testcontainers.Container + Addr string + HostID string + CountRestart int +} + +var cassNodes = make(map[string]*tcNode) +var networkName string + +func TestMain(m *testing.M) { + ctx := context.Background() + + flag.Parse() + + net, err := network.New(ctx) + if err != nil { + log.Fatal("cannot create network: ", err) + } + networkName = net.Name + + //collect cass nodes into a cluster + *flagCluster = "" + for i := 1; i <= *clusterSize; i++ { + err = NodeUpTC(ctx, i) + if err != nil { + log.Fatalf("Failed to start Cassandra node %d: %v", i, err) + } + } + + if err := assignHostID(); err != nil { + log.Fatalf("Failed to assign Cassandra host ID: %v", err) + } + + // run all tests + code := m.Run() + + os.Exit(code) +} + +func NodeUpTC(ctx context.Context, number int) error { + cassandraVersion := flagCassVersion.String()[1:] + + jvmOpts := "-Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler" + if *clusterSize == 1 { + jvmOpts += " -Dcassandra.skip_wait_for_gossip_to_settle=0" + } + + env := map[string]string{ + "JVM_OPTS": jvmOpts, + "CASSANDRA_SEEDS": "node1", + "CASSANDRA_DC": "datacenter1", + "HEAP_NEWSIZE": "100M", + "MAX_HEAP_SIZE": "256M", + "CASSANDRA_RACK": "rack1", + "CASSANDRA_ENDPOINT_SNITCH": "GossipingPropertyFileSnitch", + "CASS_VERSION": cassandraVersion, + } + + if *flagRunAuthTest { + env["AUTH_TEST"] = "true" + } + + fs := []testcontainers.ContainerFile{ + { + HostFilePath: "./testdata/update_cas_config.sh", + ContainerFilePath: "/usr/local/bin/update_cas_config.sh", + FileMode: 0o777, + }, + { + HostFilePath: "./testdata/docker-entrypoint.sh", + ContainerFilePath: "/usr/local/bin/docker-entrypoint.sh", + FileMode: 0o777, + }, + } + + if *flagRunSslTest { + env["RUN_SSL_TEST"] = "true" + fs = append(fs, []testcontainers.ContainerFile{ + { + HostFilePath: "./testdata/pki/.keystore", + ContainerFilePath: "testdata/.keystore", + FileMode: 0o777, + }, + { + HostFilePath: "./testdata/pki/.truststore", + ContainerFilePath: "testdata/.truststore", + FileMode: 0o777, + }, + }...) + } + + req := testcontainers.ContainerRequest{ + Image: "cassandra:" + cassandraVersion, + Env: env, + Files: fs, + Networks: []string{networkName}, + WaitingFor: wait.ForLog("Startup complete").WithStartupTimeout(2 * time.Minute), + Name: "node" + strconv.Itoa(number), + } + + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + }) + if err != nil { + return err + } + + cIP, err := container.ContainerIP(ctx) + if err != nil { + return err + } + + if *flagRunAuthTest { + // it requires additional time to properly build Cassandra with authentication. + time.Sleep(10 * time.Second) + } + + cassNodes[req.Name] = &tcNode{ + TC: container, + Addr: cIP, + } + + *flagCluster += cIP + if *clusterSize > number { + *flagCluster += "," + } + + return nil +} + +func assignHostID() error { + cluster := createCluster() + if *flagRunAuthTest { + cluster.Authenticator = PasswordAuthenticator{ + Username: "cassandra", + Password: "cassandra", + } + } + session, err := cluster.CreateSession() + if err != nil { + return err + } + defer session.Close() + + for _, node := range cassNodes { + if host, ok := session.ring.getHostByIP(node.Addr); ok { + node.HostID = host.hostId + } else { + return fmt.Errorf("host_id for node addr: %s not found", node.Addr) + } + } + + return nil +} + +// restoreCluster is a helper function that ensures the cluster remains fully operational during topology changes. +// Commonly used in test scenarios where nodes are added, removed, or modified to maintain cluster stability and prevent downtime. +func restoreCluster(ctx context.Context) error { + for _, container := range cassNodes { + if running := container.TC.IsRunning(); running { + continue + } + if err := container.TC.Start(ctx); err != nil { + return fmt.Errorf("cannot start a container: %v", err) + } + + container.CountRestart += 1 + + err := wait.ForLog("Startup complete"). + WithStartupTimeout(60*time.Second). + WithOccurrence(container.CountRestart+1). + WaitUntilReady(ctx, container.TC) + if err != nil { + return fmt.Errorf("cannot wait until a start container: %v", err) + } + + time.Sleep(10 * time.Second) + } + + return nil +} + +// getPool is a test helper designed to enhance readability by mocking the `func (p *policyConnPool) getPool(host *HostInfo) (pool *hostConnPool, ok bool)` method. +func getPool(p *policyConnPool, hostID string) (pool *hostConnPool, ok bool) { + p.mu.RLock() + pool, ok = p.hostConnPools[hostID] + p.mu.RUnlock() + return +} diff --git a/testdata/docker-entrypoint.sh b/testdata/docker-entrypoint.sh new file mode 100644 index 000000000..416fbb984 --- /dev/null +++ b/testdata/docker-entrypoint.sh @@ -0,0 +1,97 @@ +#!/bin/bash +set -e + +# first arg is `-f` or `--some-option` +# or there are no args +if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then + set -- cassandra -f "$@" +fi + +# allow the container to be started with `--user` +if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then + find "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra \ + \! -user cassandra -exec chown cassandra '{}' + + exec gosu cassandra "$BASH_SOURCE" "$@" +fi + +_ip_address() { + # scrape the first non-localhost IP address of the container + # in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first + ip address | awk ' + $1 != "inet" { next } # only lines with ip addresses + $NF == "lo" { next } # skip loopback devices + $2 ~ /^127[.]/ { next } # skip loopback addresses + $2 ~ /^169[.]254[.]/ { next } # skip link-local addresses + { + gsub(/\/.+$/, "", $2) + print $2 + exit + } + ' +} + +# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example) +_sed-in-place() { + local filename="$1"; shift + local tempFile + tempFile="$(mktemp)" + sed "$@" "$filename" > "$tempFile" + cat "$tempFile" > "$filename" + rm "$tempFile" +} + +if [ "$1" = 'cassandra' ]; then + : ${CASSANDRA_RPC_ADDRESS='0.0.0.0'} + + : ${CASSANDRA_LISTEN_ADDRESS='auto'} + if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then + CASSANDRA_LISTEN_ADDRESS="$(_ip_address)" + fi + + : ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"} + + if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then + CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)" + fi + : ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS} + + if [ -n "${CASSANDRA_NAME:+1}" ]; then + : ${CASSANDRA_SEEDS:="cassandra"} + fi + : ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"} + + _sed-in-place "$CASSANDRA_CONF/cassandra.yaml" \ + -r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' + + for yaml in \ + broadcast_address \ + broadcast_rpc_address \ + cluster_name \ + endpoint_snitch \ + listen_address \ + num_tokens \ + rpc_address \ + start_rpc \ + ; do + var="CASSANDRA_${yaml^^}" + val="${!var}" + if [ "$val" ]; then + _sed-in-place "$CASSANDRA_CONF/cassandra.yaml" \ + -r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' + fi + done + + for rackdc in dc rack; do + var="CASSANDRA_${rackdc^^}" + val="${!var}" + if [ "$val" ]; then + _sed-in-place "$CASSANDRA_CONF/cassandra-rackdc.properties" \ + -r 's/^('"$rackdc"'=).*/\1 '"$val"'/' + fi + done +fi + +# execute custom script +./usr/local/bin/update_cas_config.sh + +exec "$@" diff --git a/testdata/update_cas_config.sh b/testdata/update_cas_config.sh new file mode 100755 index 000000000..89469c02f --- /dev/null +++ b/testdata/update_cas_config.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +# Path to the cassandra.yaml file inside the container +CASSANDRA_CONFIG="/etc/cassandra/cassandra.yaml" + +# Function to update a property in the cassandra.yaml file +update_property() { + local property=$1 + local value=$2 + local root_property=${property%%.*} + local nested_property=${property#*.} + + local indent="" + if [[ $CASS_VERSION == 4.0.* ]]; then + indent=" " + else + indent=" " + fi + + if grep -q "^${property}:" "$CASSANDRA_CONFIG"; then + # If the property exists, update its value + sed -i "s|^\(${property}:\).*|\1 ${value}|" "$CASSANDRA_CONFIG" + else + if [[ "$property" == *"."* ]]; then + # If it's a nested property + if grep -q "^${root_property}:" "$CASSANDRA_CONFIG"; then + if grep -q "^${indent}# ${nested_property}:" "$CASSANDRA_CONFIG"; then + # Check if the nested property is commented out + sed -i "/^${root_property}:/,/^[^ ]/ s|^\(${indent}# ${nested_property}:\).*|${indent}${nested_property}: ${value}|" "$CASSANDRA_CONFIG" + elif grep -q "^${indent}${nested_property}:" "$CASSANDRA_CONFIG"; then + echo "Added nested_property $nested_property into root_property $root_property with value $value" + sed -i "/^${root_property}:/,/^[^ ]/ s|^\(${indent}${nested_property}:\).*|\1 ${value}|" "$CASSANDRA_CONFIG" + else + # Add nested property under existing root property + awk -v root="$root_property" -v prop="$nested_property" -v val="$value" -v ind="$indent" ' + $0 ~ "^"root":" { + print $0 + print ind prop": "val + next + } + { print $0 } + ' "$CASSANDRA_CONFIG" > /tmp/tmpfile && mv /tmp/tmpfile "$CASSANDRA_CONFIG" + fi + else + # Add new root property with nested property + echo -e "${root_property}:\n${indent}${nested_property}: ${value}" >> "$CASSANDRA_CONFIG" + fi + else + # If it's a root-level property, add it directly + echo "${property}: ${value}" >> "$CASSANDRA_CONFIG" + fi + fi +} + +# Function to configure Cassandra based on the version +configure_cassandra() { + local keypath="testdata" + local conf=( + "concurrent_reads:2" + "concurrent_writes:2" + ) + + if [[ $AUTH_TEST == true ]]; then + if [[ $CASS_VERSION == 5.*.* ]]; then + conf+=( + "authenticator.class_name :org.apache.cassandra.auth.PasswordAuthenticator" + "authorizer: CassandraAuthorizer" + ) + else + conf+=( + "authenticator: PasswordAuthenticator" + "authorizer: CassandraAuthorizer" + ) + fi +fi + + if [[ $RUN_SSL_TEST == true ]]; then + conf+=( + "client_encryption_options.enabled:true" + "client_encryption_options.keystore:$keypath/.keystore" + "client_encryption_options.keystore_password:cassandra" + "client_encryption_options.require_client_auth:true" + "client_encryption_options.truststore:$keypath/.truststore" + "client_encryption_options.truststore_password:cassandra" + ) + fi + + if [[ $CASS_VERSION == 3.*.* ]]; then + conf+=( + "rpc_server_type:sync" + "rpc_min_threads:2" + "rpc_max_threads:2" + "enable_user_defined_functions:true" + "enable_materialized_views:true" + "write_request_timeout_in_ms:5000" + "read_request_timeout_in_ms:5000" + ) + elif [[ $CASS_VERSION == 4.0.* ]]; then + conf+=( + "enable_user_defined_functions:true" + "enable_materialized_views:true" + "write_request_timeout_in_ms:5000" + "read_request_timeout_in_ms:5000" + ) + else + conf+=( + "user_defined_functions_enabled:true" + "materialized_views_enabled:true" + "write_request_timeout:5000ms" + "read_request_timeout:5000ms" + ) + fi + + for setting in "${conf[@]}"; do + IFS=":" read -r property value <<< "$setting" + update_property "$property" "$value" + done + + # Update rpc addresses with the container's IP address + IP_ADDRESS=$(hostname -i) + sed -i "s/^rpc_address:.*/rpc_address: $IP_ADDRESS/" /etc/cassandra/cassandra.yaml + sed -i "s/^# broadcast_rpc_address:.*/broadcast_rpc_address: $IP_ADDRESS/" /etc/cassandra/cassandra.yaml + + echo "Cassandra configuration modified successfully." +} + +## update Cassandra config +configure_cassandra