Skip to content

Commit

Permalink
Fixed Unexpected EOF error when batch Insert
Browse files Browse the repository at this point in the history
Replace table entities with Go SDK (issue #2519)
  • Loading branch information
blueww committed Dec 24, 2024
1 parent 78a07e2 commit 6b27839
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 52 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Blob:

- GetBlob on Archive tier blobs now fails as expected.

Table:

- Fixed "Unexpected EOF" error when batch InsertReplace entities with Go SDK (issue #2519)

## 2024.10 Version 3.33.0

General:
Expand Down
4 changes: 2 additions & 2 deletions src/table/batch/TableBatchSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class TableBatchSerialization extends BatchSerialization {
this.SerializeEntityPath(serializedResponses, request);

if (null !== response.eTag && undefined !== response.eTag) {
serializedResponses += "ETag: " + response.eTag;
serializedResponses += "ETag: " + response.eTag + "\r\n";
}
return serializedResponses;
}
Expand Down Expand Up @@ -251,7 +251,7 @@ export class TableBatchSerialization extends BatchSerialization {
);

if (null !== response.eTag && undefined !== response.eTag) {
serializedResponses += "ETag: " + response.eTag;
serializedResponses += "ETag: " + response.eTag + "\r\n";
}
return serializedResponses;
}
Expand Down
110 changes: 60 additions & 50 deletions tests/table/go/main.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package main

import (
"context"
"encoding/json"
"context"
"encoding/json"
"fmt"
"strings"
"fmt"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/data/aztables"
"github.com/google/uuid"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/data/aztables"
"github.com/Azure/azure-sdk-for-go/storage"
"github.com/google/uuid"
)

/*
This simple test written in go uses the Azure Table Storage SDK for Go to create a table,
insert some entities as a batch, and query the table for those entities.
This is to reproduce and ensure that we have not introduced any MIME Serialization bugs for
the Azure Go SDK.
the Azure Go SDK.
I use the modified samples from the SDK and the Go SDK team to create this test and validate
the behavior of Azurite:
https://github.com/Azure/azure-sdk-for-go/tree/sdk/data/aztables/v1.0.1/sdk/data/aztables/
*/
func main() {
var svc *aztables.ServiceClient
var svc *aztables.ServiceClient
// use a unique table name for each test run
tableName := "go" + strings.Replace(uuid.New().String(), "-", "", -1)
svc = login()
Expand All @@ -36,50 +37,50 @@ func main() {
/*
Creates the service client for Azurite
*/
func login() (*aztables.ServiceClient) {
connStr := "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
svc, err := aztables.NewServiceClientFromConnectionString(connStr, nil)
handle(err)
func login() *aztables.ServiceClient {
connStr := "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
svc, err := aztables.NewServiceClientFromConnectionString(connStr, nil)
handle(err)
return svc
}

func createTable(svc *aztables.ServiceClient, tableName string) {
_, err := svc.CreateTable(context.TODO(), tableName, nil)
handle(err)
handle(err)
}

/*
Create a client for the table to be able to create entities etc.
*/
func createTableClient(service *aztables.ServiceClient, tableName string) (*aztables.Client) {
func createTableClient(service *aztables.ServiceClient, tableName string) *aztables.Client {
client := service.NewClient(tableName)

return client
}

/*
Inserts several entities, using SDK's aztables modules for Go
*/
func insertSimple(client *aztables.Client) {

for i := 0; i < 10; i++ {

entity := createEntity(i)

marshalled, err := json.Marshal(entity)
handle(err)

_, err = client.AddEntity(context.TODO(), marshalled, nil)
handle(err)
}

}

func createEntity(i int)(aztables.EDMEntity){
func createEntity(i int) aztables.EDMEntity {
return aztables.EDMEntity{
Entity: aztables.Entity{
PartitionKey: "pencils",
RowKey: fmt.Sprintf("%d", i),
PartitionKey: "pencils",
RowKey: fmt.Sprintf("%d", i),
},
Properties: map[string]interface{}{
"Product": "Ticonderoga Pencils",
Expand Down Expand Up @@ -108,6 +109,17 @@ func insertBatch(tableName string, partitionkey string, rowkey string) {

t := ts.GetTableReference("InsertBatchTestTable")

tb := t.NewBatch()

// insert
entity1 := t.GetEntityReference(partitionkey, "rowkey1")
tb.InsertEntity(entity1)

// InsertOrReplace
entity2 := t.GetEntityReference(partitionkey, `rowkey2`)
tb.InsertOrReplaceEntity(entity2, true)

//InsertOrMerge
entity := t.GetEntityReference(partitionkey, rowkey)

props := map[string]interface{}{
Expand All @@ -120,8 +132,6 @@ func insertBatch(tableName string, partitionkey string, rowkey string) {

entity.Properties = props

tb := t.NewBatch()

tb.InsertOrMergeEntity(entity, true)

if err := tb.ExecuteBatch(); err != nil {
Expand All @@ -144,34 +154,34 @@ func insertBatch(tableName string, partitionkey string, rowkey string) {
func query(client *aztables.Client) {

filter := "PartitionKey eq 'pencils'"
options := &aztables.ListEntitiesOptions{
Filter: &filter,
Select: to.Ptr("RowKey,Value,Product,Available"),
Top: to.Ptr(int32(15)),
}

pager := client.NewListEntitiesPager(options)
pageCount := 0
for pager.More() {
response, err := pager.NextPage(context.TODO())
handle(err)

fmt.Printf("There are %d entities in page #%d\n", len(response.Entities), pageCount)
pageCount += 1

for _, entity := range response.Entities {
var myEntity aztables.EDMEntity
err = json.Unmarshal(entity, &myEntity)
handle(err)

fmt.Printf("Received: %v, %v, %v, %v\n", myEntity.RowKey, myEntity.Properties["Value"], myEntity.Properties["Product"], myEntity.Properties["Available"])
}
}
options := &aztables.ListEntitiesOptions{
Filter: &filter,
Select: to.Ptr("RowKey,Value,Product,Available"),
Top: to.Ptr(int32(15)),
}

pager := client.NewListEntitiesPager(options)
pageCount := 0
for pager.More() {
response, err := pager.NextPage(context.TODO())
handle(err)

fmt.Printf("There are %d entities in page #%d\n", len(response.Entities), pageCount)
pageCount += 1

for _, entity := range response.Entities {
var myEntity aztables.EDMEntity
err = json.Unmarshal(entity, &myEntity)
handle(err)

fmt.Printf("Received: %v, %v, %v, %v\n", myEntity.RowKey, myEntity.Properties["Value"], myEntity.Properties["Product"], myEntity.Properties["Available"])
}
}
}

func handle(err error) {
if err != nil {
fmt.Println(err)
panic(err)
}
}
}

0 comments on commit 6b27839

Please sign in to comment.