Ejemplo n.º 1
0
 public FirestoreTestClass(String parent,
                           Firestore.FirestoreClient fsClient,
                           FirestoreAdmin.FirestoreAdminClient fsAdminClient,
                           String baseCollectionId)
 {
     Parent           = parent;
     FsClient         = fsClient;
     FsAdminClient    = fsAdminClient;
     BaseCollectionId = baseCollectionId;
     Utils            = new FirestoreTestUtils();
     ClearTransactionId();
 }
Ejemplo n.º 2
0
        public static void document(Firestore.FirestoreClient client, ref Dictionary <string, long> metrics)
        {
            ListDocumentsRequest list_document_request = new ListDocumentsRequest();

            list_document_request.Parent = _PARENT_RESOURCE;

            stopwatch.Start();
            client.ListDocuments(list_document_request);
            stopwatch.Stop();


            long lantency = stopwatch.ElapsedMilliseconds;

            metrics.Add("list_documents_latency_ms", lantency);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.Title = typeof(MainClass).Name;
            var parent = "projects/mch-test-49bba/databases/(default)";

            Console.Title = parent;

            Boolean debug = false;

            if (args.Length > 0 && args[0] == "--debug")
            {
                debug = true;
            }

            if (debug)
            {
                Console.WriteLine("GOOGLE_APPLICATION_CREDENTIALS: " + Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
                var storage = StorageClient.Create();
                var buckets = storage.ListBuckets("mch-test-49bba");
                foreach (var bucket in buckets)
                {
                    Console.WriteLine(bucket.Name);
                }
            }

            GoogleCredential credential = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));

            if (credential == null)
            {
                Console.WriteLine("Could not create credential from file.");
                Console.WriteLine("GOOGLE_APPLICATION_CREDENTIALS: " + Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
            }
            Grpc.Core.Channel channel = new Grpc.Core.Channel(
                "firestore.googleapis.com:443",
                GoogleGrpcCredentials.ToChannelCredentials(credential)
                );

            Firestore.FirestoreClient           fsClient      = new Firestore.FirestoreClient(channel);
            FirestoreAdmin.FirestoreAdminClient fsAdminClient = new FirestoreAdmin.FirestoreAdminClient(channel);

            String baseCollectionId = "GrpcTestData";

            Ftc = new FirestoreTestClass(parent, fsClient, fsAdminClient, baseCollectionId);

            Run();
        }
Ejemplo n.º 4
0
        public static void executeProbes(string api)
        {
            StackdriverUtilClass util = new StackdriverUtilClass(api);
            GoogleCredential     auth = GoogleCredential.GetApplicationDefault();
            //GoogleCredential auth = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
            ClientBase          client;
            ProbeTestsBaseClass test;

            System.Type type;

            Dictionary <string, string> probe_functions = new Dictionary <string, string>();

            if (api == "firestore")
            {
                Grpc.Core.Channel channel = new Grpc.Core.Channel(_FIRESTORE_TARGET, GoogleGrpcCredentials.ToChannelCredentials(auth));
                client          = new Firestore.FirestoreClient(channel);
                test            = new FirestoreProbesTestClass();
                probe_functions = (test as FirestoreProbesTestClass).GetProbFunctions();
                type            = typeof(FirestoreProbesTestClass);
            }
            else if (api == "spanner")
            {
                Grpc.Core.Channel channel = new Grpc.Core.Channel(_SPANNER_TARGET, GoogleGrpcCredentials.ToChannelCredentials(auth));
                client          = new Spanner.SpannerClient(channel);
                test            = new SpannerProbesTestClass();
                probe_functions = (test as SpannerProbesTestClass).GetProbFunctions();
                type            = typeof(SpannerProbesTestClass);
            }
            else
            {
                Console.WriteLine("grpc not implemented for {0}", api);
                return;
            }

            //object value = test.GetType().GetMethod("GetProbFunctions").Invoke(test,null);
            //probe_functions = value.GetType().GetProperties()

            int total   = probe_functions.Count;
            int success = 0;
            Dictionary <string, long> metrics = new Dictionary <string, long>();

            foreach (var probe in probe_functions)
            {
                Console.WriteLine("{0}", probe.Key);
                MethodInfo fun        = type.GetMethod(probe.Value);
                object[]   parameters = new object[] { client, metrics };

                try
                {
                    if (api == "firestore")
                    {
                        fun.Invoke((test as FirestoreProbesTestClass), parameters);
                    }
                    else
                    {
                        fun.Invoke((test as SpannerProbesTestClass), parameters);
                    }

                    success++;
                }
                catch (Exception error)
                {
                    Console.WriteLine("{0}", error);
                    util.reportError(error);
                }
            }

            if (success == total)
            {
                util.setSuccess(true);
            }
            util.addMetrics(metrics);
            util.outputMetrics();

            if (success != total)
            {
                return;
            }
        }