コード例 #1
0
        /// <inheritdoc />
        public override async Task RunScenarioAsync()
        {
            // Create the "music" keyspace
            Console.WriteLine();
            Console.WriteLine("Creating keyspace: music");
            RowSet rowSet = await CreateKeyspaceHelper.CreateKeyspaceAsync(this.Session, "music");

            Console.WriteLine(
                "Created keyspace: music. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Create the tables necessary for the music service
            Console.WriteLine();
            //await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));
            Console.WriteLine($"Creating table: tracks with provisioned throughput: {ScenarioBase.DefaultThroughputForQuickstart}");
            rowSet = await CreateTableHelpers.CreateTableWithThroughputInCQLAsync(
                this.Session,
                "CREATE TABLE IF NOT EXISTS music.tracks (id text PRIMARY KEY, title text, durationms int, album text, artist text, genre text)",
                ScenarioBase.DefaultThroughputForQuickstart);

            Console.WriteLine(
                "Created table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Insert some tracks using prepared statements, one record at a time
            double totalRUConsumed = 0;

            Console.WriteLine();
            Console.WriteLine($"Preparing statement for inserting records into the tracks table");
            PreparedStatement preparedStatement = await this.Session.PrepareAsync("INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES (?,?,?,?,?, 'Pop')");

            Console.WriteLine($"Prepared statement with id.  Consumed RU: {0:F2}", CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(preparedStatement));

            rowSet = await this.Session.ExecuteAsync(preparedStatement.Bind("2wYHz0GOHV49Xezd5mWTDP", "Falling", 201385, "Falling", "Lina Mayer"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(preparedStatement.Bind("5SxkdsY1ufZzoq9iXceLw9", "No Tears Left To Cry", 205947, "No Tears Left To Cry", "Ariana Grande"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(preparedStatement.Bind("2ARqIya5NAuvFVHSN3bL0m", "The Middle", 184732, "The Middle", "Zedd"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(preparedStatement.Bind("0BlY60NrN0fFWbdW3RW40q", "Never Be the Same", 184732, "Never Be the Same", "Camila Cabello"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(preparedStatement.Bind("6T8cJz5lAqGer9GUHGyelE", "Gods Plan", 198960, "Scary Hours", "Drake"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            Console.WriteLine("Inserted 5 records. Consumed RU: {0:F2}", totalRUConsumed);

            // Read a single track
            string trackId = "6T8cJz5lAqGer9GUHGyelE";

            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            PreparedStatement readPreparedStatement = await this.Session.PrepareAsync("SELECT * FROM music.tracks WHERE id=?");

            rowSet = await this.Session.ExecuteAsync(readPreparedStatement.Bind(trackId));

            Row track = rowSet.GetRows().First();

            Console.WriteLine(
                "Read track: {0}, title: {1} duration: {2} from album: {3}. Consumed RU: {4:F2}",
                trackId,
                track.GetValue <string>("title"),
                track.GetValue <int>("durationms"),
                track.GetValue <string>("album"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Update a single track
            Console.WriteLine();
            Console.WriteLine($"Updating duration of track: '{trackId}'");
            preparedStatement = await this.Session.PrepareAsync("UPDATE music.tracks SET durationms = 227077 WHERE id=?");

            rowSet = await this.Session.ExecuteAsync(preparedStatement.Bind(trackId));

            Console.WriteLine(
                "Updated duration of track: {0}.  Consumed RU: {1:F2}",
                trackId,
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Read a single track
            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(readPreparedStatement.Bind(trackId));

            track = rowSet.GetRows().First();
            Console.WriteLine(
                "Read track: {0}, title: {1} duration: {2} from album: {3}. Consumed RU: {4:F2}",
                trackId,
                track.GetValue <string>("title"),
                track.GetValue <int>("durationms"),
                track.GetValue <string>("album"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Delete a single track.
            Console.WriteLine();
            Console.WriteLine($"Deleting track: '{trackId}'");
            preparedStatement = await this.Session.PrepareAsync("DELETE FROM music.tracks WHERE id=?");

            rowSet = await this.Session.ExecuteAsync(preparedStatement.Bind(trackId));

            Console.WriteLine(
                "Deleted track: {0}. Consumed RU: {1:F2}",
                trackId,
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Drop the table
            Console.WriteLine();
            Console.WriteLine($"Droping table: tracks ");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));

            Console.WriteLine(
                "Dropped table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));
        }
コード例 #2
0
        /// <inheritdoc />
        public override async Task RunScenarioAsync()
        {
            // Create the "music" keyspace
            Console.WriteLine();
            Console.WriteLine("Creating keyspace: music");
            RowSet rowSet = await CreateKeyspaceHelper.CreateKeyspaceAsync(this.Session, "music");

            Console.WriteLine(
                "Created keyspace: music. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Create the tables necessary for the music service, with default TTL value of 10 seconds
            Console.WriteLine();
            //await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));
            Console.WriteLine($"Creating table: tracks with provisioned throughput: {ScenarioBase.DefaultThroughputForQuickstart} and default TTL: {TimeToLiveScenario.DefaultTableTTL}");
            rowSet = await CreateTableHelpers.CreateTableWithThroughputInCQLAsync(
                this.Session,
                $"CREATE TABLE IF NOT EXISTS music.tracks (id text PRIMARY KEY, title text, durationms int, album text, artist text, genre text)",
                ScenarioBase.DefaultThroughputForQuickstart,
                TimeToLiveScenario.DefaultTableTTL);

            Console.WriteLine(
                "Created table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Insert one track using the default TTL
            double totalRUConsumed = 0;

            Console.WriteLine();
            Console.WriteLine($"Inserting record into the tracks table (default TTL)");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement(
                                                         "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('2wYHz0GOHV49Xezd5mWTDP', 'Falling', 201385,'Falling','Lina Mayer', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            Console.WriteLine("Inserted 1 record. Consumed RU: {0:F2}", totalRUConsumed);

            // Delay the execution to wait for TTL expiry
            Console.Write($"Delaying execution for {TimeToLiveScenario.DefaultTableTTL} seconds");
            await Task.Delay(TimeSpan.FromSeconds(TimeToLiveScenario.DefaultTableTTL * 2));

            // Read a single track
            string trackId = "2wYHz0GOHV49Xezd5mWTDP";

            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"SELECT * FROM music.tracks WHERE id='{trackId}'"));

            int trackCount = rowSet.GetRows().Count();

            if (trackCount != 0)
            {
                throw new InvalidOperationException($"Expected no rows to be returned.  Service returned {trackCount} rows");
            }

            Console.WriteLine(
                "Read 0 rows from the system. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Insert one track using the custom TTL
            int customRecordTTL = 20;

            Console.WriteLine();
            Console.WriteLine($"Inserting record into the tracks table (custom TTL: {customRecordTTL} seconds)");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement(
                                                         $"INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('2wYHz0GOHV49Xezd5mWTDP', 'Falling', 201385,'Falling','Lina Mayer', 'Pop') USING TTL {customRecordTTL}"));

            Console.WriteLine("Inserted 1 record. Consumed RU: {0:F2}", CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Delay the execution to wait for TTL expiry
            Console.WriteLine($"Delaying execution for {TimeToLiveScenario.DefaultTableTTL} seconds");
            await Task.Delay(TimeSpan.FromSeconds(TimeToLiveScenario.DefaultTableTTL + 3));

            // Read a single track.  Record should exist as custom ttl is greater than default ttl
            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"SELECT * FROM music.tracks WHERE id='{trackId}'"));

            Row track = rowSet.GetRows().First();

            Console.WriteLine(
                "Read track: {0}, title: {1} duration: {2} from album: {3}. Consumed RU: {4:F2}",
                trackId,
                track.GetValue <string>("title"),
                track.GetValue <int>("durationms"),
                track.GetValue <string>("album"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Drop the table
            Console.WriteLine();
            Console.WriteLine($"Droping table: tracks ");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));

            Console.WriteLine(
                "Dropped table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));
        }
コード例 #3
0
        /// <inheritdoc />
        public override async Task RunScenarioAsync()
        {
            // Create the "music" keyspace
            Console.WriteLine();
            Console.WriteLine("Creating keyspace: music");
            RowSet rowSet = await CreateKeyspaceHelper.CreateKeyspaceAsync(this.Session, "music");

            Console.WriteLine(
                "Created keyspace: music. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Create the tables necessary for the music service
            Console.WriteLine();
            //await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));
            Console.WriteLine($"Creating table: tracks with provisioned throughput: {ScenarioBase.DefaultThroughputForQuickstart}");
            rowSet = await CreateTableHelpers.CreateTableWithThroughputInCQLAsync(
                this.Session,
                "CREATE TABLE IF NOT EXISTS music.tracks (id text PRIMARY KEY, title text, durationms int, album text, artist text, genre text)",
                ScenarioBase.DefaultThroughputForQuickstart);

            Console.WriteLine(
                "Created table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Insert one track
            double totalRUConsumed = 0;

            Console.WriteLine();
            Console.WriteLine($"Inserting records into the tracks table");
            string msg =
                "INSERT INTO music.tracks JSON '{\"id\": \"2wYHz0GOHV49Xezd5mWTDP\", \"title\": \"Falling\", \"durationms\": 201385, \"album\": \"Falling\", \"artist\":\"Lina Mayer\", \"genre\": \"Pop\"}'";

            rowSet = await this.Session.ExecuteAsync(new SimpleStatement(
                                                         "INSERT INTO music.tracks JSON '{\"id\": \"2wYHz0GOHV49Xezd5mWTDP\", \"title\": \"Falling\", \"durationms\": 201385, \"album\": \"Falling\", \"artist\":\"Lina Mayer\", \"genre\": \"Pop\"}'"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            Console.WriteLine("Inserted 1 record. Consumed RU: {0:F2}", totalRUConsumed);

            // Read a single track
            string trackId = "2wYHz0GOHV49Xezd5mWTDP";

            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"SELECT JSON * FROM music.tracks WHERE id='{trackId}'"));

            Row track = rowSet.GetRows().First();

            Console.WriteLine(
                "Read track: {0}, json: {1}. Consumed RU: {2:F2}",
                trackId,
                track.GetValue <string>("[json]"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Drop the table
            Console.WriteLine();
            Console.WriteLine($"Droping table: tracks ");
            //rowSet = await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));
            Console.WriteLine(
                "Dropped table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));
        }
コード例 #4
0
        /// <inheritdoc />
        public override async Task RunScenarioAsync()
        {
            // Create the "music" keyspace
            Console.WriteLine();
            Console.WriteLine("Creating keyspace: music");
            RowSet rowSet = await CreateKeyspaceHelper.CreateKeyspaceAsync(this.Session, "music");

            Console.WriteLine(
                "Created keyspace: music. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Create the tables necessary for the music service
            Console.WriteLine();
            //await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));
            Console.WriteLine($"Creating table: tracks with provisioned throughput: {ScenarioBase.DefaultThroughputForQuickstart}");
            rowSet = await CreateTableHelpers.CreateTableWithThroughputInCQLAsync(
                this.Session,
                "CREATE TABLE IF NOT EXISTS music.tracks (id text PRIMARY KEY, title text, durationms int, album text, artist text, genre text)",
                ScenarioBase.DefaultThroughputForQuickstart);

            Console.WriteLine(
                "Created table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Insert some tracks, one record at a time
            double totalRUConsumed = 0;

            Console.WriteLine();
            Console.WriteLine($"Inserting records into the tracks table - Using INSERT");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement(
                                                         "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('2wYHz0GOHV49Xezd5mWTDP', 'Falling', 201385,'Falling','Lina Mayer', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(new SimpleStatement(
                                                                   "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('5SxkdsY1ufZzoq9iXceLw9', 'No Tears Left To Cry', 205947,'No Tears Left To Cry','Ariana Grande', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(new SimpleStatement(
                                                                   "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('2ARqIya5NAuvFVHSN3bL0m', 'The Middle', 184732,'The Middle','Zedd', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(new SimpleStatement(
                                                                   "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('0BlY60NrN0fFWbdW3RW40q', 'Never Be the Same', 184732,'Never Be the Same ','Camila Cabello', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            rowSet           = await this.Session.ExecuteAsync(new SimpleStatement(
                                                                   "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('6T8cJz5lAqGer9GUHGyelE', 'Gods Plan', 198960,'Scary Hours','Drake', 'Pop')"));

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            Console.WriteLine("Inserted 5 records. Consumed RU: {0:F2}", totalRUConsumed);

            // Insert some tracks using BATCH
            Console.WriteLine();
            Console.WriteLine($"Inserting records into the tracks table - Using BATCH");
            BatchStatement batchStatement = new BatchStatement()
                                            .SetBatchType(BatchType.Unlogged)
                                            .Add(new SimpleStatement(
                                                     "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('6mrKP2jyIQmM0rw6fQryjr', 'Let You Down', 212120,'Perception','NF', 'Pop')"))
                                            .Add(new SimpleStatement(
                                                     "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('08bNPGLD8AhKpnnERrAc6G', 'FRIENDS', 202621,'FRIENDS','Marshmello', 'Pop')"))
                                            .Add(new SimpleStatement(
                                                     "INSERT INTO music.tracks (id, title, durationms, album, artist, genre) VALUES ('7fCNUWi6uflDTQ08srxMZk', 'No Excuses', 152862,'No Excuses','Meghan Trainor', 'Pop')"));

            rowSet = await this.Session.ExecuteAsync(batchStatement);

            totalRUConsumed += CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet);
            Console.WriteLine("Inserted 3 records. Consumed RU: {0:F2}", totalRUConsumed);

            // Read a single track
            string trackId = "6T8cJz5lAqGer9GUHGyelE";

            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"SELECT * FROM music.tracks WHERE id='{trackId}'"));

            Row track = rowSet.GetRows().First();

            Console.WriteLine(
                "Read track: {0}, title: {1} duration: {2} from album: {3}. Consumed RU: {4:F2}",
                trackId,
                track.GetValue <string>("title"),
                track.GetValue <int>("durationms"),
                track.GetValue <string>("album"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Update a single track
            Console.WriteLine();
            Console.WriteLine($"Updating duration of track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"UPDATE music.tracks SET durationms = 227077 WHERE id='{trackId}'"));

            Console.WriteLine(
                "Updated duration of track: {0}.  Consumed RU: {1:F2}",
                trackId,
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Read a single track
            Console.WriteLine();
            Console.WriteLine($"Reading track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"SELECT * FROM music.tracks WHERE id='{trackId}'"));

            track = rowSet.GetRows().First();
            Console.WriteLine(
                "Read track: {0}, title: {1} duration: {2} from album: {3}. Consumed RU: {4:F2}",
                trackId,
                track.GetValue <string>("title"),
                track.GetValue <int>("durationms"),
                track.GetValue <string>("album"),
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Delete a single track.
            Console.WriteLine();
            Console.WriteLine($"Deleting track: '{trackId}'");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement($"DELETE FROM music.tracks WHERE id='{trackId}'"));

            Console.WriteLine(
                "Deleted track: {0}. Consumed RU: {1:F2}",
                trackId,
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));

            // Drop the table
            Console.WriteLine();
            Console.WriteLine($"Droping table: tracks ");
            rowSet = await this.Session.ExecuteAsync(new SimpleStatement("DROP TABLE IF EXISTS music.tracks"));

            Console.WriteLine(
                "Dropped table: tracks. Consumed RU: {0:F2}",
                CustomPayloadHelpers.ExtractRequestChargeFromCustomPayload(rowSet));
        }