Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 1591d04

Browse files
authored
Add GetServerVersion() api method and update dataset log positions / tests (#128)
* Add GetServerVersion() api method to add ability to retrieve server version * Update datasets with real prepare/commit log positions Update read stream tests to cater for log position changes on the server Context: kurrent-io/EventStore#3459
1 parent 6843d82 commit 1591d04

5 files changed

+109
-55
lines changed

esdb/impl.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ func (handle *connectionHandle) SupportsFeature(feature int) bool {
161161
return false
162162
}
163163

164+
func (handle *connectionHandle) GetServerVersion() (*ServerVersion, error) {
165+
if handle.Id() == uuid.Nil {
166+
return nil, &Error{
167+
code: ErrorCodeConnectionClosed,
168+
err: fmt.Errorf("connection is closed"),
169+
}
170+
}
171+
172+
if handle.serverInfo == nil {
173+
// old server without support for server features api
174+
return &ServerVersion{}, nil
175+
}
176+
177+
return &handle.serverInfo.version, nil
178+
}
179+
164180
func newErroredConnectionHandle(err error) connectionHandle {
165181
return connectionHandle{
166182
id: uuid.Nil,
@@ -311,12 +327,6 @@ func createGrpcConnection(conf *Configuration, address string) (*grpc.ClientConn
311327
return conn, nil
312328
}
313329

314-
type serverVersion struct {
315-
major int
316-
minor int
317-
patch int
318-
}
319-
320330
const (
321331
featureNothing = 0
322332
featureBatchAppend = 1
@@ -329,7 +339,7 @@ const (
329339
)
330340

331341
type serverInfo struct {
332-
version serverVersion
342+
version ServerVersion
333343
featureFlags int
334344
}
335345

@@ -350,7 +360,7 @@ func getSupportedMethods(ctx context.Context, conf *Configuration, conn *grpc.Cl
350360
}
351361

352362
info := serverInfo{
353-
version: serverVersion{},
363+
version: ServerVersion{},
354364
featureFlags: featureNothing,
355365
}
356366

@@ -367,11 +377,11 @@ func getSupportedMethods(ctx context.Context, conf *Configuration, conn *grpc.Cl
367377

368378
switch idx {
369379
case 0:
370-
info.version.major = num
380+
info.version.Major = num
371381
case 1:
372-
info.version.minor = num
382+
info.version.Minor = num
373383
default:
374-
info.version.patch = num
384+
info.version.Patch = num
375385
}
376386
}
377387

esdb/operations.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package esdb
2+
3+
// ServerVersion Represents the version of an EventStoreDB node.
4+
type ServerVersion struct {
5+
Major int
6+
Minor int
7+
Patch int
8+
}
9+
10+
// GetServerVersion Returns the version of the EventStoreDB node to which the client is currently connected.
11+
func (client *Client) GetServerVersion() (*ServerVersion, error) {
12+
handle, err := client.grpcClient.getConnectionHandle()
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
return handle.GetServerVersion();
18+
}

esdb/read_stream_test.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"io"
88
"io/ioutil"
9+
"math"
910
"testing"
1011
"time"
1112

@@ -92,15 +93,28 @@ func readStreamEventsForwardsFromZeroPosition(db *esdb.Client) TestCall {
9293

9394
assert.Equal(t, numberOfEvents, uint64(len(events)), "Expected the correct number of messages to be returned")
9495

96+
serverVersion, err := db.GetServerVersion()
97+
if err != nil {
98+
t.Fatalf("Failed to retrieve server version %+v", err)
99+
}
100+
101+
isAtLeast22_6 := serverVersion.Major == 22 && serverVersion.Minor >= 6 || serverVersion.Major > 22;
102+
95103
for i := 0; i < numberOfEventsToRead; i++ {
96104
assert.Equal(t, testEvents[i].Event.EventID, events[i].OriginalEvent().EventID)
97105
assert.Equal(t, testEvents[i].Event.EventType, events[i].OriginalEvent().EventType)
98106
assert.Equal(t, testEvents[i].Event.StreamID, events[i].OriginalEvent().StreamID)
99107
assert.Equal(t, testEvents[i].Event.StreamRevision.Value, events[i].OriginalEvent().EventNumber)
100108
assert.Equal(t, testEvents[i].Event.Created.Nanos, events[i].OriginalEvent().CreatedDate.Nanosecond())
101109
assert.Equal(t, testEvents[i].Event.Created.Seconds, events[i].OriginalEvent().CreatedDate.Unix())
102-
assert.Equal(t, testEvents[i].Event.Position.Commit, events[i].OriginalEvent().Position.Commit)
103-
assert.Equal(t, testEvents[i].Event.Position.Prepare, events[i].OriginalEvent().Position.Prepare)
110+
if isAtLeast22_6 {
111+
assert.Equal(t, testEvents[i].Event.Position.Commit, events[i].OriginalEvent().Position.Commit)
112+
assert.Equal(t, testEvents[i].Event.Position.Prepare, events[i].OriginalEvent().Position.Prepare)
113+
} else {
114+
assert.Equal(t, uint64(math.MaxUint64), events[i].OriginalEvent().Position.Commit)
115+
assert.Equal(t, uint64(math.MaxUint64), events[i].OriginalEvent().Position.Prepare)
116+
}
117+
104118
assert.Equal(t, testEvents[i].Event.ContentType, events[i].OriginalEvent().ContentType)
105119
}
106120
}
@@ -149,15 +163,27 @@ func readStreamEventsBackwardsFromEndPosition(db *esdb.Client) TestCall {
149163

150164
assert.Equal(t, numberOfEvents, uint64(len(events)), "Expected the correct number of messages to be returned")
151165

166+
serverVersion, err := db.GetServerVersion()
167+
if err != nil {
168+
t.Fatalf("Failed to retrieve server version %+v", err)
169+
}
170+
171+
isAtLeast22_6 := serverVersion.Major == 22 && serverVersion.Minor >= 6 || serverVersion.Major > 22;
172+
152173
for i := 0; i < numberOfEventsToRead; i++ {
153174
assert.Equal(t, testEvents[i].Event.EventID, events[i].OriginalEvent().EventID)
154175
assert.Equal(t, testEvents[i].Event.EventType, events[i].OriginalEvent().EventType)
155176
assert.Equal(t, testEvents[i].Event.StreamID, events[i].OriginalEvent().StreamID)
156177
assert.Equal(t, testEvents[i].Event.StreamRevision.Value, events[i].OriginalEvent().EventNumber)
157178
assert.Equal(t, testEvents[i].Event.Created.Nanos, events[i].OriginalEvent().CreatedDate.Nanosecond())
158179
assert.Equal(t, testEvents[i].Event.Created.Seconds, events[i].OriginalEvent().CreatedDate.Unix())
159-
assert.Equal(t, testEvents[i].Event.Position.Commit, events[i].OriginalEvent().Position.Commit)
160-
assert.Equal(t, testEvents[i].Event.Position.Prepare, events[i].OriginalEvent().Position.Prepare)
180+
if isAtLeast22_6 {
181+
assert.Equal(t, testEvents[i].Event.Position.Commit, events[i].OriginalEvent().Position.Commit)
182+
assert.Equal(t, testEvents[i].Event.Position.Prepare, events[i].OriginalEvent().Position.Prepare)
183+
} else {
184+
assert.Equal(t, uint64(math.MaxUint64), events[i].OriginalEvent().Position.Commit)
185+
assert.Equal(t, uint64(math.MaxUint64), events[i].OriginalEvent().Position.Prepare)
186+
}
161187
assert.Equal(t, testEvents[i].Event.ContentType, events[i].OriginalEvent().ContentType)
162188
}
163189
}

resources/test/dataset20M-1800-e0-e10.json

+20-20
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"nanos": 245917000
5555
},
5656
"position": {
57-
"prepare": 18446744073709551615,
58-
"commit": 18446744073709551615
57+
"prepare": 11607400,
58+
"commit": 11607400
5959
},
6060
"contentType": "application/json"
6161
}
@@ -115,8 +115,8 @@
115115
"nanos": 245936000
116116
},
117117
"position": {
118-
"prepare": 18446744073709551615,
119-
"commit": 18446744073709551615
118+
"prepare": 11607557,
119+
"commit": 11607557
120120
},
121121
"contentType": "application/json"
122122
}
@@ -176,8 +176,8 @@
176176
"nanos": 245940000
177177
},
178178
"position": {
179-
"prepare": 18446744073709551615,
180-
"commit": 18446744073709551615
179+
"prepare": 11607714,
180+
"commit": 11607714
181181
},
182182
"contentType": "application/json"
183183
}
@@ -237,8 +237,8 @@
237237
"nanos": 245943000
238238
},
239239
"position": {
240-
"prepare": 18446744073709551615,
241-
"commit": 18446744073709551615
240+
"prepare": 11607871,
241+
"commit": 11607871
242242
},
243243
"contentType": "application/json"
244244
}
@@ -298,8 +298,8 @@
298298
"nanos": 245955000
299299
},
300300
"position": {
301-
"prepare": 18446744073709551615,
302-
"commit": 18446744073709551615
301+
"prepare": 11608028,
302+
"commit": 11608028
303303
},
304304
"contentType": "application/json"
305305
}
@@ -359,8 +359,8 @@
359359
"nanos": 245958000
360360
},
361361
"position": {
362-
"prepare": 18446744073709551615,
363-
"commit": 18446744073709551615
362+
"prepare": 11608185,
363+
"commit": 11608185
364364
},
365365
"contentType": "application/json"
366366
}
@@ -420,8 +420,8 @@
420420
"nanos": 245962000
421421
},
422422
"position": {
423-
"prepare": 18446744073709551615,
424-
"commit": 18446744073709551615
423+
"prepare": 11608342,
424+
"commit": 11608342
425425
},
426426
"contentType": "application/json"
427427
}
@@ -481,8 +481,8 @@
481481
"nanos": 245964000
482482
},
483483
"position": {
484-
"prepare": 18446744073709551615,
485-
"commit": 18446744073709551615
484+
"prepare": 11608499,
485+
"commit": 11608499
486486
},
487487
"contentType": "application/json"
488488
}
@@ -542,8 +542,8 @@
542542
"nanos": 245968000
543543
},
544544
"position": {
545-
"prepare": 18446744073709551615,
546-
"commit": 18446744073709551615
545+
"prepare": 11608656,
546+
"commit": 11608656
547547
},
548548
"contentType": "application/json"
549549
}
@@ -603,8 +603,8 @@
603603
"nanos": 245970000
604604
},
605605
"position": {
606-
"prepare": 18446744073709551615,
607-
"commit": 18446744073709551615
606+
"prepare": 11608813,
607+
"commit": 11608813
608608
},
609609
"contentType": "application/json"
610610
}

resources/test/dataset20M-1800-e1999-e1990.json

+20-20
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"nanos": 521770000
5555
},
5656
"position": {
57-
"prepare": 18446744073709551615,
58-
"commit": 18446744073709551615
57+
"prepare": 12237319,
58+
"commit": 12237319
5959
},
6060
"contentType": "application/json"
6161
}
@@ -115,8 +115,8 @@
115115
"nanos": 521767000
116116
},
117117
"position": {
118-
"prepare": 18446744073709551615,
119-
"commit": 18446744073709551615
118+
"prepare": 12237162,
119+
"commit": 12237162
120120
},
121121
"contentType": "application/json"
122122
}
@@ -176,8 +176,8 @@
176176
"nanos": 521765000
177177
},
178178
"position": {
179-
"prepare": 18446744073709551615,
180-
"commit": 18446744073709551615
179+
"prepare": 12237005,
180+
"commit": 12237005
181181
},
182182
"contentType": "application/json"
183183
}
@@ -237,8 +237,8 @@
237237
"nanos": 521762000
238238
},
239239
"position": {
240-
"prepare": 18446744073709551615,
241-
"commit": 18446744073709551615
240+
"prepare": 12236848,
241+
"commit": 12236848
242242
},
243243
"contentType": "application/json"
244244
}
@@ -298,8 +298,8 @@
298298
"nanos": 521759000
299299
},
300300
"position": {
301-
"prepare": 18446744073709551615,
302-
"commit": 18446744073709551615
301+
"prepare": 12236691,
302+
"commit": 12236691
303303
},
304304
"contentType": "application/json"
305305
}
@@ -359,8 +359,8 @@
359359
"nanos": 521756000
360360
},
361361
"position": {
362-
"prepare": 18446744073709551615,
363-
"commit": 18446744073709551615
362+
"prepare": 12236534,
363+
"commit": 12236534
364364
},
365365
"contentType": "application/json"
366366
}
@@ -420,8 +420,8 @@
420420
"nanos": 521753000
421421
},
422422
"position": {
423-
"prepare": 18446744073709551615,
424-
"commit": 18446744073709551615
423+
"prepare": 12236377,
424+
"commit": 12236377
425425
},
426426
"contentType": "application/json"
427427
}
@@ -481,8 +481,8 @@
481481
"nanos": 521750000
482482
},
483483
"position": {
484-
"prepare": 18446744073709551615,
485-
"commit": 18446744073709551615
484+
"prepare": 12236220,
485+
"commit": 12236220
486486
},
487487
"contentType": "application/json"
488488
}
@@ -542,8 +542,8 @@
542542
"nanos": 521748000
543543
},
544544
"position": {
545-
"prepare": 18446744073709551615,
546-
"commit": 18446744073709551615
545+
"prepare": 12236063,
546+
"commit": 12236063
547547
},
548548
"contentType": "application/json"
549549
}
@@ -603,8 +603,8 @@
603603
"nanos": 521745000
604604
},
605605
"position": {
606-
"prepare": 18446744073709551615,
607-
"commit": 18446744073709551615
606+
"prepare": 12235906,
607+
"commit": 12235906
608608
},
609609
"contentType": "application/json"
610610
}

0 commit comments

Comments
 (0)