Go语言 如何在github actions上使用aerospike和testcontainers

lsmepo6l  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(113)

我正在尝试用github操作在testcontainers上运行aerospike,
我有时会得到一个错误,有时不会,当我在github上运行这个动作时,我得到的错误如下:

integration_test.go:124: error getting aerospike client: error creating cluster client: aero client failed to connect to [127.0.0.1]:32772 timeout:10s: ResultCode: INVALID_NODE_ERROR, Iteration: 0, InDoubt: false, Node: <nil>: Failed to connect to hosts: [127.0.0.1:32772]

下面是我的气刺式配置

service {
    user root
    group root
    # Number of nodes where the replica count is automatically reduced to 1.
    # paxos-single-replica-limit 1
    # pidfile /var/run/aerospike/asd.pid
    proto-fd-max 15000
    query-threads-limit 100
}

logging {
    # Log file must be an absolute path.
    file ${LOGFILE} {
        context any critical
    }

    # Send log messages to stdout
    console {
        context any info
    }
}

network {
    service {
        address any
        port 3000

        # Uncomment the following to set the `access-address` parameter to the
        # IP address of the Docker host. This will the allow the server to correctly
        # publish the address which applications and other nodes in the cluster to
        # use when addressing this node.
        # access-address <IPADDR>
    }

    heartbeat {
        address any
        # mesh is used for environments that do not support multicast
        mode mesh
        port 3002

        # use asinfo -v 'tip:host=<ADDR>;port=3002' to inform cluster of
        # other mesh nodes

        interval 150
        timeout 10
    }

    fabric {
        address any
        port 3001 
    }
}

namespace persistent00 {
  replication-factor 1
  memory-size 20M
  storage-engine memory
  nsup-period 86400
}

这是我如何通过使用测试容器进行连接

func startContainer(ctx context.Context) (*aerospikeContainer, error) {
    req := testcontainers.ContainerRequest{
        Image:        "aerospike/aerospike-server:6.2.0.12",
        ExposedPorts: []string{"3000/tcp", "3001/tcp", "3002/tcp"},
        Files: []testcontainers.ContainerFile{
            {
                HostFilePath:      "aerospike.conf",
                ContainerFilePath: "aerospike.conf",
            },
        },
        Cmd: []string{"--config-file", "aerospike.conf"},
        WaitingFor: wait.ForAll(
            wait.ForListeningPort("3000/tcp"),
            wait.ForLog("{persistent00} migrations: complete").WithOccurrence(2),
        ),
    }

    container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
        ContainerRequest: req,
        Started:          true,
    })
    if err != nil {
        return nil, err
    }

    return &aerospikeContainer{Container: container}, nil
}

我该怎么做才能让它工作?
我尝试使用心跳和增加withOccurence,但它似乎仍然不工作

egmofgnx

egmofgnx1#

此线程建议在遇到INVALID_NODE_ERROR时将客户端(在您的情况下是Go客户端)升级到最新版本:https://discuss.aerospike.com/t/invalid-node-error-code-3-after-some-writes/6037/9
JDogMcSteezy的评论是有意义的,如果它有时发生,而不是总是发生(客户端试图连接到Aerospike之前,Aerospike是可达的),waitingFor应该在这种情况下有所帮助。
我不熟悉Go语言,但你可以在这里看到一个使用Aerospike和testcontainers的稳定Java示例,它利用Playtika的公共库来使用Aerospike和testcontainers:https://github.com/aerospike/spring-data-aerospike
Playtika的testcontainers依赖:https://github.com/aerospike/spring-data-aerospike/blob/main/pom.xml#L256
这是testcontainers的配置文件,默认情况下只包含Aerospike的版本:https://github.com/aerospike/spring-data-aerospike/blob/main/src/test/resources/bootstrap.properties
这是测试中的配置类:https://github.com/aerospike/spring-data-aerospike/blob/main/src/test/java/org/springframework/data/aerospike/config/BlockingTestConfig.java#L30

相关问题