Skip to content

Commit

Permalink
endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkrishnads committed Aug 19, 2024
1 parent 8328baa commit 1e4677a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 21 deletions.
93 changes: 86 additions & 7 deletions quest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"
Expand Down Expand Up @@ -404,11 +405,89 @@ func TestSmokeGetRetention(t *testing.T) {

func TestActivateHotTier(t *testing.T) {
CreateStream(t, NewGlob.QueryClient, NewGlob.Stream)
activateHotTier(t)
disableHotTier(t)
activateHotTier(t, "", true)
disableHotTier(t, false)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
}

func TestActivateNonExistentHotTier(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

status, _ := activateHotTier(t, "", false)
require.NotEqualf(t, status, 200, "Hot tier was activated for a non-existent stream.")
}

func TestHotTierWithTimePartition(t *testing.T) {
time_partition_stream := NewGlob.Stream + "timepartition"
timeHeader := map[string]string{"X-P-Time-Partition": "source_time", "X-P-Time-Partition-Limit": "365d"}
CreateStreamWithHeader(t, NewGlob.QueryClient, time_partition_stream, timeHeader)

payload := StreamHotTier{
Size: "20 Gib",
}
jsonPayload, _ := json.Marshal(payload)

req, _ := NewGlob.QueryClient.NewRequest("PUT", "logstream/"+time_partition_stream+"/hottier", bytes.NewBuffer(jsonPayload))
req.Header.Set("Content-Type", "application/json")
response, _ := NewGlob.QueryClient.Do(req)
body := readAsString(response.Body)

require.NotEqualf(t, response.StatusCode, 200, "Hot tier activation succeeded for time partition with message: %s, but was expected to fail", body)
}

func TestHotTierHugeDiskSize(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

CreateStream(t, NewGlob.QueryClient, NewGlob.Stream)
status, _ := activateHotTier(t, "500GiB", false) // activate hot tier with huge disk size
require.NotEqualf(t, status, 200, "Hot tier was activated for a non-existent stream.")
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
}

func TestHotTierIncreaseSize(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

CreateStream(t, NewGlob.QueryClient, NewGlob.Stream)
activateHotTier(t, "", true)
status, err := activateHotTier(t, "30 GiB", false) // increase disk size
require.Equalf(t, 200, status, "Increasing disk size of hot tier failed with error: %s", err)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
}

func TestHotTierDecreaseSize(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

CreateStream(t, NewGlob.QueryClient, NewGlob.Stream)
activateHotTier(t, "", true)
status, message := activateHotTier(t, "10 GiB", false) // decrease disk size
require.NotEqualf(t, 200, status, "Decreasing disk size of hot tier should fail but succeeded with message: %s", message)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
}

func TestGetNonExistentHotTier(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

getHotTierStatus(t, true)
}

func DisableNonExistentHotTier(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

disableHotTier(t, true)
}

// create stream, put hot tier, ingest data for a duration, wait for 2-3 mins to see if all data is available in hot tier
func TestHotTierGetsLogs(t *testing.T) {
if NewGlob.IngestorUrl.String() == "" {
Expand All @@ -417,11 +496,11 @@ func TestHotTierGetsLogs(t *testing.T) {

// DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
createAndIngest(t)
activateHotTier(t)
activateHotTier(t, "", true)
time.Sleep(2 * 60 * time.Second) // wait 2 minutes for hot tier to sync

htCount := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)
disableHotTier(t)
disableHotTier(t, false)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)

require.Equalf(t, htCount, `[{"count":200}]`, "Ingested 200 logs, but hot tier contains %s", htCount)
Expand All @@ -441,11 +520,11 @@ func TestHotTierGetsLogsAfter(t *testing.T) {

// create a second stream with hot tier
createAndIngest(t)
activateHotTier(t)
activateHotTier(t, "", true)
time.Sleep(2 * 60 * time.Second) // wait 2 minutes for hot tier to sync

htCount := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)
disableHotTier(t)
disableHotTier(t, false)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)

require.Equalf(t, prevCount, htCount, "With hot tier disabled, the count was %s but with it, the count is %s", prevCount, htCount)
Expand All @@ -460,7 +539,7 @@ func TestHotTierLogCount(t *testing.T) {
createAndIngest(t)
countBefore := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)

activateHotTier(t)
activateHotTier(t, "", true)
time.Sleep(60 * 2 * time.Second) // wait for 2 minutes to allow hot tier to sync

countAfter := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)
Expand Down
45 changes: 31 additions & 14 deletions test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,27 +581,35 @@ func checkAPIAccess(t *testing.T, client HTTPClient, stream string, role string)
}
}

func activateHotTier(t *testing.T) {
func activateHotTier(t *testing.T, size string, verify bool) (int, string) {
if size == "" {
size = "20 GiB" // default hot tier size
}

payload := StreamHotTier{
Size: "20 GiB", // set hot tier size to be 20 GB
Size: size,
}
json, _ := json.Marshal(payload)
jsonPayload, _ := json.Marshal(payload)

req, _ := NewGlob.QueryClient.NewRequest("PUT", "logstream/"+NewGlob.Stream+"/hottier", bytes.NewBuffer(json))
req, _ := NewGlob.QueryClient.NewRequest("PUT", "logstream/"+NewGlob.Stream+"/hottier", bytes.NewBuffer(jsonPayload))
req.Header.Set("Content-Type", "application/json")
response, err := NewGlob.QueryClient.Do(req)
body := readAsString(response.Body)

if NewGlob.IngestorUrl.String() != "" {
require.Equalf(t, 200, response.StatusCode, "Server returned unexpected http code: %s and response: %s", response.Status, body)
require.NoErrorf(t, err, "Activating hot tier failed in distributed mode: %s", err)
} else {
// right now, hot tier is unavailable in standalone so anything other than 200 is fine
require.NotEqualf(t, 200, response.StatusCode, "Hot tier has been activated in standalone mode: %s and response: %s", response.Status, body)
if verify {
if NewGlob.IngestorUrl.String() != "" {
require.Equalf(t, 200, response.StatusCode, "Server returned unexpected http code: %s and response: %s", response.Status, body)
require.NoErrorf(t, err, "Activating hot tier failed in distributed mode: %s", err)
} else {
// right now, hot tier is unavailable in standalone so anything other than 200 is fine
require.NotEqualf(t, 200, response.StatusCode, "Hot tier has been activated in standalone mode: %s and response: %s", response.Status, body)
}
}

return response.StatusCode, body
}

func getHotTierStatus(t *testing.T) *StreamHotTier {
func getHotTierStatus(t *testing.T, shouldFail bool) *StreamHotTier {
req, err := NewGlob.QueryClient.NewRequest("GET", "logstream/"+NewGlob.Stream+"/hottier", nil)
require.NoError(t, err, "Failed to create request")

Expand All @@ -613,7 +621,11 @@ func getHotTierStatus(t *testing.T) *StreamHotTier {

body := readAsString(response.Body)

require.Equal(t, 200, response.StatusCode, "GET hot tier failed with status code: %d & body: %s", response.StatusCode, body)
if shouldFail {
require.NotEqualf(t, 200, response.StatusCode, "Hot tier was expected to fail but succeeded with body: %s", body)
} else {
require.Equalf(t, 200, response.StatusCode, "GET hot tier failed with status code: %d & body: %s", response.StatusCode, body)
}

var hotTierStatus StreamHotTier
err = json.Unmarshal([]byte(body), &hotTierStatus)
Expand All @@ -622,11 +634,16 @@ func getHotTierStatus(t *testing.T) *StreamHotTier {
return &hotTierStatus
}

func disableHotTier(t *testing.T) {
func disableHotTier(t *testing.T, shouldFail bool) {
req, _ := NewGlob.QueryClient.NewRequest("DELETE", "logstream/"+NewGlob.Stream+"/hottier", nil)
response, err := NewGlob.QueryClient.Do(req)
body := readAsString(response.Body)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s and response: %s", response.Status, body)

if shouldFail {
require.NotEqualf(t, 200, response.StatusCode, "Non-existent hot tier was disabled with response: %s", body)
} else {
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s and response: %s", response.Status, body)
}
require.NoErrorf(t, err, "Disabling hot tier failed: %s", err)
}

Expand Down

0 comments on commit 1e4677a

Please sign in to comment.