Skip to content

Commit

Permalink
DeleteSegmentRsv
Browse files Browse the repository at this point in the history
  • Loading branch information
juagargi committed Jun 23, 2020
1 parent 4c1aa23 commit 6984151
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
24 changes: 22 additions & 2 deletions go/cs/reservation/reservationdbtest/reservationdbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestDB(t *testing.T, db TestableDB) {
"get segment reservations from src/dst": testGetSegmentRsvsFromSrcDstIA,
"get segment reservation from path": testGetSegmentRsvFromPath,
"get segment reservation from IF pair": testGetSegmentRsvsFromIFPair,
"delete segment reservation": testDeleteSegmentRsv,
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -309,6 +310,27 @@ func testGetSegmentRsvsFromIFPair(ctx context.Context, t *testing.T, db backend.
require.Error(t, err)
}

func testDeleteSegmentRsv(ctx context.Context, t *testing.T, db backend.DB) {
r := newTestReservation(t)
err := db.NewSegmentRsv(ctx, r)
require.NoError(t, err)
err = db.DeleteSegmentRsv(ctx, &r.ID)
require.NoError(t, err)
rsv, err := db.GetSegmentRsvFromID(ctx, &r.ID)
require.NoError(t, err)
require.Nil(t, rsv)
// with no indices
r = newTestReservation(t)
r.Indices = segment.Indices{}
err = db.NewSegmentRsv(ctx, r)
require.NoError(t, err)
err = db.DeleteSegmentRsv(ctx, &r.ID)
require.NoError(t, err)
rsv, err = db.GetSegmentRsvFromID(ctx, &r.ID)
require.NoError(t, err)
require.Nil(t, rsv)
}

// newToken just returns a token that can be serialized. This one has two HopFields.
func newToken() *reservation.Token {
t, err := reservation.TokenFromRaw(xtest.MustParseHexString(
Expand Down Expand Up @@ -336,5 +358,3 @@ func newTestReservation(t *testing.T) *segment.Reservation {
require.NoError(t, err)
return r
}

// TODO(juagargi) test the transactions
4 changes: 2 additions & 2 deletions go/cs/reservation/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func (x *executor) DeleteExpiredIndices(ctx context.Context, now time.Time) (int
}

// DeleteSegmentRsv removes the segment reservation
func (x *executor) DeleteSegmentRsv(ctx context.Context, ID reservation.SegmentID) error {
return nil
func (x *executor) DeleteSegmentRsv(ctx context.Context, ID *reservation.SegmentID) error {
return deleteSegmentRsv(ctx, x.db, ID)
}

// GetE2ERsvFromID finds the end to end resevation given its ID.
Expand Down
2 changes: 0 additions & 2 deletions go/cs/reservation/sqlite/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const (
// to prevent data corruption between incompatible database schemas.
SchemaVersion = 1
// Schema is the SQLite database layout.
// TODO(juagargi) explain the DB structure here or in the design markdown.
// TODO(juagargi) create appropriate SQL indices.
// TODO(juagargi) path should be unique if not null
Schema = `CREATE TABLE seg_reservation (
row_id INTEGER,
id_as INTEGER NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion go/cs/reservationstorage/backend/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type ReserverAndTransit interface {
// PersistSegmentRsv ensures the DB contains the reservation as represented in rsv.
PersistSegmentRsv(ctx context.Context, rsv *segment.Reservation) error
// DeleteSegmentRsv removes the segment reservation. Used in teardown.
DeleteSegmentRsv(ctx context.Context, ID reservation.SegmentID) error
DeleteSegmentRsv(ctx context.Context, ID *reservation.SegmentID) error

// DeleteExpiredIndices will remove expired indices from the DB. If a reservation is left
// without any index after removing the expired ones, it will also be removed.
Expand Down

0 comments on commit 6984151

Please sign in to comment.