Commit 0643161e authored by Marshall Pierce's avatar Marshall Pierce
Browse files

Extend set cluster version example

parent 198bbf00
Loading
Loading
Loading
Loading
+19 −23
Original line number Diff line number Diff line
@@ -4,44 +4,40 @@

#include "kinetic/kinetic.h"

#include "command_line_flags.h"

using kinetic::KineticConnectionFactory;
using kinetic::Status;
using kinetic::KineticRecord;

using std::unique_ptr;

int main(int argc, char* argv[]) {
    if (argc != 4) {
        printf("%s: <host> <port> <new cluster version>\n", argv[0]);
        return 1;
    }

    const char* host = argv[1];
    int port = atoi(argv[2]);
    int new_cluster_version = atoi(argv[3]);

    printf("Setting cluster version of %s:%d to %d\n", host, port, new_cluster_version);

    kinetic::ConnectionOptions options;
    options.host = host;
    options.port = port;
    options.user_id = 1;
    options.hmac_key = "asdfasdf";
DEFINE_int64(new_cluster_version, 1, "New cluster version");

    kinetic::KineticConnectionFactory kinetic_connection_factory = kinetic::NewKineticConnectionFactory();
int main(int argc, char* argv[]) {
    printf("Setting cluster version of %s:%" PRId64 " to %" PRId64 "\n", FLAGS_host.c_str(), FLAGS_port, FLAGS_new_cluster_version);

    unique_ptr<kinetic::ConnectionHandle> connection;
    if (!kinetic_connection_factory.NewConnection(options, 5, connection).ok()) {
        printf("Unable to connect\n");
        return 1;
    }
    parse_flags(&argc, &argv, connection);

    if (!(connection->blocking().SetClusterVersion(new_cluster_version).ok())) {
    if (!(connection->blocking().SetClusterVersion(FLAGS_new_cluster_version).ok())) {
        printf("Unable to set cluster version\n");
        return 1;
    }

    printf("Finished setting cluster version\n");

    // this is not the right cluster version, so the get should fail
    connection->blocking().SetClientClusterVersion(FLAGS_new_cluster_version + 1);

    unique_ptr<KineticRecord> result = unique_ptr<KineticRecord>();
    kinetic::StatusCode code = connection->blocking().Get("foo", result).statusCode();
    if (code != kinetic::StatusCode::REMOTE_CLUSTER_VERSION_MISMATCH) {
        printf("Unexpectedly got %d\n", static_cast<int>(code));
        return 1;
    } else {
        printf("Correctly rejected a GET with incorrect cluster version\n");
    }

    return 0;
}