ribaraka commented on code in PR #1780:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1780#discussion_r1766861870


##########
main_test.go:
##########
@@ -0,0 +1,145 @@
+//go:build cassandra || integration
+// +build cassandra integration
+
+package gocql
+
+import (
+       "context"
+       "flag"
+       "fmt"
+       "log"
+       "os"
+       "strconv"
+       "testing"
+       "time"
+
+       "github.com/testcontainers/testcontainers-go"
+       "github.com/testcontainers/testcontainers-go/wait"
+)
+
+func TestMain(m *testing.M) {
+       ctx := context.Background()
+
+       flag.Parse()
+
+       cassandraVersion := flagCassVersion.String()[1:]
+
+       jvmOpts := "-Dcassandra.test.fail_writes_ks=test 
-Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
+       if *clusterSize == 1 {
+               // speeds up the creation of a single-node cluster.
+               jvmOpts += " -Dcassandra.initial_token=0 
-Dcassandra.skip_wait_for_gossip_to_settle=0"
+       }
+
+       env := map[string]string{
+               "JVM_OPTS":                  jvmOpts,
+               "CASSANDRA_SEEDS":           "cassandra1",
+               "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"
+       }
+
+       networkRequest := testcontainers.GenericNetworkRequest{
+               NetworkRequest: testcontainers.NetworkRequest{
+                       Name: "cassandra",
+               },
+       }
+       cassandraNetwork, err := testcontainers.GenericNetwork(ctx, 
networkRequest)
+       if err != nil {
+               log.Fatalf("Failed to create network: %s", err)
+       }
+       defer cassandraNetwork.Remove(ctx)
+
+       // Function to create a Cassandra container (node)
+       createCassandraContainer := func(number int) (string, error) {
+               req := testcontainers.ContainerRequest{
+                       Image:        "cassandra:" + cassandraVersion,
+                       ExposedPorts: []string{"9042/tcp"},
+                       Env:          env,
+                       Files: []testcontainers.ContainerFile{
+                               {
+                                       HostFilePath:      
"./testdata/pki/.keystore",
+                                       ContainerFilePath: "testdata/.keystore",
+                                       FileMode:          0o777,
+                               },
+                               {
+                                       HostFilePath:      
"./testdata/pki/.truststore",
+                                       ContainerFilePath: 
"testdata/.truststore",
+                                       FileMode:          0o777,
+                               },
+                               {
+                                       HostFilePath:      
"update_container_cass_config.sh",
+                                       ContainerFilePath: 
"/update_container_cass_config.sh",
+                                       FileMode:          0o777,
+                               },
+                       },
+
+                       Networks: []string{"cassandra"},
+                       LifecycleHooks: 
[]testcontainers.ContainerLifecycleHooks{{
+                               PostStarts: []testcontainers.ContainerHook{
+                                       func(ctx context.Context, c 
testcontainers.Container) error {
+                                               // wait for cassandra 
config.yaml to initialize
+                                               time.Sleep(100 * 
time.Millisecond)
+
+                                               code, _, err := c.Exec(ctx, 
[]string{"bash", "./update_container_cass_config.sh"})
+                                               if err != nil {
+                                                       return err
+                                               }
+                                               if code != 0 {
+                                                       return 
fmt.Errorf("script ./update_container_cass_config.sh exited with code %d", code)
+                                               }
+                                               return nil
+                                       },
+                               },
+                       }},

Review Comment:
   Unfortunately, your advice didn’t resolve the issue. Waiting for any logs 
didn’t yield useful results, as I was attempting to change certain Cassandra 
configuration properties on the fly. These properties can also vary depending 
on the Cassandra version in use.
   
   My solution using a hook also had flaws, as the hook couldn’t pause the 
bootstrapping process to allow the execution of custom code at the necessary 
point. As a result, my custom script couldn’t be executed in time.
   
   To address this, I made some adjustments to the docker-entrypoint, which 
successfully handled the required tasks during the initialization process.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to