Skip to content

Commit

Permalink
fix minor bug in avro
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin Jian committed Jun 11, 2020
1 parent eac19bb commit 00e2401
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 45 deletions.
71 changes: 68 additions & 3 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/storage/storage-blob-changefeed/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"editor.detectIndentation": false
},
"[json]": {
"editor.formatOnSave": true,
"editor.formatOnSave": false,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
Expand Down
18 changes: 9 additions & 9 deletions sdk/storage/storage-blob-changefeed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@azure/logger": "^1.0.0",
"@opentelemetry/api": "^0.6.1",
"events": "^3.0.0",
"tslib": "^1.10.0"
"tslib": "^2.0.0"
},
"devDependencies": {
"@azure/identity": "^1.1.0-preview",
Expand All @@ -113,11 +113,11 @@
"@rollup/plugin-replace": "^2.2.0",
"@types/mocha": "^7.0.2",
"@types/node": "^8.0.0",
"@types/sinon": "^7.0.13",
"@types/sinon": "^9.0.4",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"assert": "^1.4.1",
"cross-env": "^6.0.3",
"cross-env": "^7.0.2",
"dotenv": "^8.2.0",
"downlevel-dts": "~0.4.0",
"es6-promise": "^4.2.5",
Expand Down Expand Up @@ -145,19 +145,19 @@
"mocha-junit-reporter": "^1.18.0",
"nyc": "^14.0.0",
"prettier": "^1.16.4",
"puppeteer": "^2.0.0",
"puppeteer": "^3.3.0",
"rimraf": "^3.0.0",
"rollup": "^1.16.3",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"rollup-plugin-shim": "^1.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-visualizer": "^3.1.1",
"rollup-plugin-visualizer": "^4.0.4",
"source-map-support": "^0.5.9",
"ts-node": "^8.3.0",
"typescript": "~3.8.3",
"typescript": "~3.9.3",
"util": "^0.12.1",
"sinon": "^7.1.0"
"sinon": "^9.0.2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,14 @@ export interface BlobChangeFeedEventData {
// (undocumented)
contentLength: number;
// (undocumented)
contentOffset?: number;
// (undocumented)
contentType: string;
// (undocumented)
destinationUrl?: string;
// (undocumented)
etag: string;
// (undocumented)
recursive?: string;
// (undocumented)
requestId: string;
// (undocumented)
sequencer: string;
// (undocumented)
sourceUrl?: string;
// (undocumented)
url: string;
}

Expand All @@ -74,7 +66,7 @@ export class BlobChangeFeedEventPage {
}

// @public (undocumented)
export type BlobChangeFeedEventType = "BlobCreate" | "BlobDeleted";
export type BlobChangeFeedEventType = "UnspecifiedEventType" | "BlobCreated" | "BlobDeleted" | "BlobPropertiesUpdated" | "BlobSnapshotCreated" | "Control" | "BlobTierChanged" | "BlobAsyncOperationInitiated" | "BlobMetadataUpdated";

// @public (undocumented)
export type BlobType = "BlockBlob" | "AppendBlob" | "PageBlob";
Expand Down
26 changes: 8 additions & 18 deletions sdk/storage/storage-blob-changefeed/samples/typscript/basic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
// import { BlobChangeFeedClient } from "@azure/storage-blob-changefeed";
import { BlobChangeFeedClient } from "../../src";
import { BlobChangeFeedClient, BlobChangeFeedEvent } from "../../src";

// Load the .env file if it exists
import * as dotenv from "dotenv";
Expand All @@ -23,24 +22,15 @@ export async function main() {
sharedKeyCredential
);


const containerClient = blobServiceClient.getContainerClient("$blobchangefeed");
console.log("List container.")
for await (const item of containerClient.listBlobsFlat()) {
console.log(`${item.name}: ${item.properties.contentLength}`);
}

const changeFeedClient = new BlobChangeFeedClient(blobServiceClient);
let i = 0;
for await (const event of changeFeedClient.getChanges()) {
i++;
if (i <= 2) {
console.log(event);
} else {
break;
}

const start = new Date(Date.UTC(2020, 1, 21, 22, 30, 0)); // will be floor to 22:00
const end = new Date(Date.UTC(2020, 4, 8, 21, 10, 0)); // will be ceil to 22:00
let changeFeedEvents: BlobChangeFeedEvent[] = [];
// You can also provide just a start or end time.
for await (const event of changeFeedClient.getChanges({ start, end })) {
changeFeedEvents.push(event);
}
console.log(`event count: ${i}`);
}

main().catch((err) => {
Expand Down
42 changes: 42 additions & 0 deletions sdk/storage/storage-blob-changefeed/samples/typscript/resume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
import { BlobChangeFeedClient, BlobChangeFeedEvent } from "../../src";

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

import { setLogLevel } from "@azure/logger";
setLogLevel("info");

export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";

// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);

const changeFeedClient = new BlobChangeFeedClient(blobServiceClient);
let changeFeedEvents: BlobChangeFeedEvent[] = [];
const firstPage = await changeFeedClient.getChanges().byPage({ maxPageSize: 10 }).next();
for (const event of firstPage) {
changeFeedEvents.push(event);
}

// Resume iterating from the pervious position with the continuationToken.
for await (const eventPage of changeFeedClient.getChanges().byPage({ continuationToken: firstPage.continuationToken })) {
for (const event of eventPage) {
changeFeedEvents.push(event);
}
}
}

main().catch((err) => {
console.error("Error running sample:", err.message);
});
2 changes: 1 addition & 1 deletion sdk/storage/storage-internal-avro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"rimraf": "^3.0.0",
"rollup": "^1.16.3",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"rollup-plugin-shim": "^1.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^5.1.1",
Expand Down
10 changes: 6 additions & 4 deletions sdk/storage/storage-internal-avro/src/AvroReadableFromStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export class AvroReadableFromStream extends AvroReadable {
let chunk = this._readable.read(size);
if (chunk) {
this._position += chunk.length;

this._readable.removeListener("readable", readableCallback);
this._readable.removeListener("error", rejectCallback);
this._readable.removeListener("end", rejectCallback);
this._readable.removeListener("close", rejectCallback);

// chunk.length maybe less than desired size if the stream ends.
resolve(this.toUint8Array(chunk));
this._readable.removeListener("readable", readableCallback);
this._readable.removeListener("error", reject);
this._readable.removeListener("end", reject);
this._readable.removeListener("close", reject);
}
};

Expand Down

0 comments on commit 00e2401

Please sign in to comment.