Skip to content

Commit 4aceb7d

Browse files
authored
acc: generate increasing UUID in testserver (#3746)
When sorting requests that have UUID in it (e.g. /pipelines) it helps if order of creation matches sort order of request path.
1 parent 25fdcb2 commit 4aceb7d

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

libs/testserver/alerts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/databricks/databricks-sdk-go/service/sql"
9-
"github.com/google/uuid"
109
)
1110

1211
func (s *FakeWorkspace) AlertsUpsert(req Request, alertId string) Response {
@@ -29,7 +28,7 @@ func (s *FakeWorkspace) AlertsUpsert(req Request, alertId string) Response {
2928
}
3029
}
3130
} else {
32-
alertId = uuid.New().String()
31+
alertId = nextUUID()
3332
}
3433

3534
alert.Id = alertId

libs/testserver/catalogs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/databricks/databricks-sdk-go/service/catalog"
10-
"github.com/google/uuid"
1110
)
1211

1312
func (s *FakeWorkspace) CatalogsCreate(req Request) Response {
@@ -34,7 +33,7 @@ func (s *FakeWorkspace) CatalogsCreate(req Request) Response {
3433
CreatedBy: s.CurrentUser().UserName,
3534
UpdatedAt: time.Now().UnixMilli(),
3635
UpdatedBy: s.CurrentUser().UserName,
37-
MetastoreId: uuid.New().String(),
36+
MetastoreId: nextUUID(),
3837
Owner: s.CurrentUser().UserName,
3938
CatalogType: catalog.CatalogTypeManagedCatalog,
4039
}

libs/testserver/clusters.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/databricks/databricks-sdk-go/service/compute"
8-
"github.com/google/uuid"
98
)
109

1110
func (s *FakeWorkspace) ClustersCreate(req Request) any {
@@ -19,7 +18,7 @@ func (s *FakeWorkspace) ClustersCreate(req Request) any {
1918

2019
defer s.LockUnlock()()
2120

22-
clusterId := uuid.New().String()
21+
clusterId := nextUUID()
2322
request.ClusterId = clusterId
2423
s.Clusters[clusterId] = request
2524

libs/testserver/dashboards.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/databricks/databricks-sdk-go/service/dashboards"
88
"github.com/databricks/databricks-sdk-go/service/workspace"
9-
"github.com/google/uuid"
109
)
1110

1211
func (s *FakeWorkspace) DashboardCreate(req Request) Response {
@@ -20,7 +19,7 @@ func (s *FakeWorkspace) DashboardCreate(req Request) Response {
2019
}
2120

2221
// Lakeview API strips hyphens from a uuid for dashboards
23-
dashboard.DashboardId = strings.ReplaceAll(uuid.New().String(), "-", "")
22+
dashboard.DashboardId = strings.ReplaceAll(nextUUID(), "-", "")
2423

2524
// All dashboards are active by default:
2625
dashboard.LifecycleState = dashboards.LifecycleStateActive
@@ -61,7 +60,7 @@ func (s *FakeWorkspace) DashboardCreate(req Request) Response {
6160
return Response{
6261
Body: dashboards.Dashboard{
6362
DashboardId: dashboard.DashboardId,
64-
Etag: uuid.New().String(),
63+
Etag: nextUUID(),
6564
},
6665
}
6766
}
@@ -77,7 +76,7 @@ func (s *FakeWorkspace) DashboardUpdate(req Request) Response {
7776
}
7877

7978
// Update the etag for the dashboard.
80-
dashboard.Etag = uuid.New().String()
79+
dashboard.Etag = nextUUID()
8180

8281
// All dashboards are active by default:
8382
dashboard.LifecycleState = dashboards.LifecycleStateActive

libs/testserver/database_instances.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/databricks/databricks-sdk-go/service/database"
10-
"github.com/google/uuid"
1110
)
1211

1312
var ForceSendFields []string = []string{
@@ -29,7 +28,7 @@ func (s *FakeWorkspace) DatabaseInstanceCreate(req Request) Response {
2928
}
3029

3130
// set default fields:
32-
databaseInstance.Uid = uuid.New().String()
31+
databaseInstance.Uid = nextUUID()
3332
databaseInstance.State = database.DatabaseInstanceStateAvailable
3433
databaseInstance.PgVersion = "PG_VERSION_16"
3534
databaseInstance.EffectiveNodeCount = 1

libs/testserver/fake_workspace.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package testserver
22

33
import (
44
"bytes"
5+
"encoding/binary"
56
"encoding/json"
67
"fmt"
78
"path"
@@ -12,6 +13,7 @@ import (
1213

1314
"github.com/databricks/databricks-sdk-go/service/compute"
1415
"github.com/databricks/databricks-sdk-go/service/database"
16+
"github.com/google/uuid"
1517

1618
"github.com/databricks/databricks-sdk-go/service/apps"
1719
"github.com/databricks/databricks-sdk-go/service/catalog"
@@ -63,6 +65,14 @@ func nextID() int64 {
6365
return lastID
6466
}
6567

68+
func nextUUID() string {
69+
var b [16]byte
70+
binary.BigEndian.PutUint64(b[0:8], uint64(nextID()))
71+
binary.BigEndian.PutUint64(b[8:16], uint64(nextID()))
72+
u := uuid.Must(uuid.FromBytes(b[:]))
73+
return u.String()
74+
}
75+
6676
type FileEntry struct {
6777
Info workspace.ObjectInfo
6878
Data []byte

libs/testserver/pipelines.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/databricks/databricks-sdk-go/service/pipelines"
9-
"github.com/google/uuid"
109
)
1110

1211
func (s *FakeWorkspace) PipelineGet(pipelineId string) Response {
@@ -39,7 +38,7 @@ func (s *FakeWorkspace) PipelineCreate(req Request) Response {
3938
var r pipelines.GetPipelineResponse
4039
r.Spec = &spec
4140

42-
pipelineId := uuid.New().String()
41+
pipelineId := nextUUID()
4342
r.PipelineId = pipelineId
4443
r.CreatorUserName = "[email protected]"
4544
r.LastModified = time.Now().UnixMilli()
@@ -104,7 +103,7 @@ func (s *FakeWorkspace) PipelineStartUpdate(pipelineId string) Response {
104103
}
105104
}
106105

107-
updateId := uuid.New().String()
106+
updateId := nextUUID()
108107
s.PipelineUpdates[updateId] = true
109108

110109
return Response{

libs/testserver/registered_models.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/databricks/databricks-sdk-go/service/catalog"
10-
"github.com/google/uuid"
1110
)
1211

1312
func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response {
@@ -35,7 +34,7 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response {
3534
CreatedBy: s.CurrentUser().UserName,
3635
UpdatedAt: time.Now().UnixMilli(),
3736
UpdatedBy: s.CurrentUser().UserName,
38-
MetastoreId: uuid.New().String(),
37+
MetastoreId: nextUUID(),
3938
Owner: s.CurrentUser().UserName,
4039
}
4140

libs/testserver/sql_warehouses.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/databricks/databricks-sdk-go/service/sql"
9-
"github.com/google/uuid"
109
)
1110

1211
func (s *FakeWorkspace) SqlWarehousesUpsert(req Request, warehouseId string) Response {
@@ -29,7 +28,7 @@ func (s *FakeWorkspace) SqlWarehousesUpsert(req Request, warehouseId string) Res
2928
}
3029
}
3130
} else {
32-
warehouseId = uuid.New().String()
31+
warehouseId = nextUUID()
3332
}
3433
warehouse.Id = warehouseId
3534
warehouse.Name = warehouseId

libs/testserver/volumes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/databricks/databricks-sdk-go/service/catalog"
9-
"github.com/google/uuid"
109
)
1110

1211
func (s *FakeWorkspace) VolumesCreate(req Request) Response {
@@ -31,7 +30,7 @@ func (s *FakeWorkspace) VolumesCreate(req Request) Response {
3130
}
3231
}
3332
// QQQ first UUID should be constant per workspace?
34-
volume.StorageLocation = fmt.Sprintf("s3://deco-uc-prod-isolated-aws-us-east-1/metastore/%s/volumes/%s", uuid.New().String(), uuid.New().String())
33+
volume.StorageLocation = fmt.Sprintf("s3://deco-uc-prod-isolated-aws-us-east-1/metastore/%s/volumes/%s", nextUUID(), nextUUID())
3534

3635
defer s.LockUnlock()()
3736

0 commit comments

Comments
 (0)