Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Debug Perf test/framework with storage-blob #12653

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/test-utils/perfstress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
},
"devDependencies": {
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/storage-blob": "^12.3.0",
"@types/node": "^8.0.0",
"@types/node-fetch": "^2.5.0",
"dotenv": "^8.2.0",
"eslint": "^6.1.0",
"karma": "^5.1.0",
"karma-chrome-launcher": "^3.0.0",
Expand Down
4 changes: 3 additions & 1 deletion sdk/test-utils/perfstress/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Exception } from "./exception.spec";
import { PerfStressPolicyTest } from "./perfStressPolicy.spec";
import { SleepTest } from "./sleep.spec";
import { NodeFetchTest } from "./nodeFetch.spec";
import { StorageBlobDownloadTest } from "./storage-blob.spec";

console.log("=== Starting the perfStress test ===");

Expand All @@ -24,7 +25,8 @@ const perfStressProgram = new PerfStressProgram(
Exception,
PerfStressPolicyTest,
SleepTest,
NodeFetchTest
NodeFetchTest,
StorageBlobDownloadTest
])
);

Expand Down
67 changes: 67 additions & 0 deletions sdk/test-utils/perfstress/test/storage-blob.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest, PerfStressOptionDictionary } from "../src";

import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

type OptionNames = "url";

export class StorageBlobDownloadTest extends PerfStressTest<string> {
public options: PerfStressOptionDictionary<OptionNames> = {
url: {
required: true,
description: "Required option",
shortName: "u",
longName: "url",
defaultValue: "http://bing.com",
value: "http://bing.com"
}
};
// Enter your storage account name and shared key
account = process.env.ACCOUNT_NAME || "";
accountKey = process.env.ACCOUNT_KEY || "";

sharedKeyCredential = new StorageSharedKeyCredential(this.account, this.accountKey);

blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${this.account}.blob.core.windows.net`,
this.sharedKeyCredential
);
protected static containerName = `newcontainer${new Date().getTime()}`;
protected static blobName = `newblob${new Date().getTime()}`;

public async globalSetup() {
const containerClient = this.blobServiceClient.getContainerClient(
StorageBlobDownloadTest.containerName
);

const createContainerResponse = await containerClient.create();
console.log(
`Create container ${StorageBlobDownloadTest.containerName} successfully`,
createContainerResponse.requestId
);

// Create a blob
const content = "hello world";
const blockBlobClient = containerClient.getBlockBlobClient(StorageBlobDownloadTest.blobName);
const uploadBlobResponse = await blockBlobClient.upload(content, Buffer.byteLength(content));
console.log(
`Upload block blob ${StorageBlobDownloadTest.blobName} successfully`,
uploadBlobResponse.requestId
);
}

async runAsync(): Promise<void> {
await this.blobServiceClient
.getContainerClient(StorageBlobDownloadTest.containerName)
.getBlockBlobClient(StorageBlobDownloadTest.blobName)
.download(0);
console.log("success");
}
}