diff --git a/quest_test.go b/quest_test.go index b64792e..f7086a9 100644 --- a/quest_test.go +++ b/quest_test.go @@ -18,6 +18,7 @@ package main import ( "bytes" + "encoding/json" "fmt" "os/exec" "strings" @@ -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() == "" { @@ -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) @@ -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) @@ -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) diff --git a/test_utils.go b/test_utils.go index 44079bd..6cbc08d 100644 --- a/test_utils.go +++ b/test_utils.go @@ -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") @@ -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) @@ -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) }