adamantal commented on a change in pull request #141:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/141#discussion_r444992030



##########
File path: pkg/events/event_cache_test.go
##########
@@ -0,0 +1,170 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package events
+
+import (
+       "testing"
+       "time"
+
+       "gotest.tools/assert"
+
+       "github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si"
+)
+
+func TestStartStop(t *testing.T) {
+       cache := GetEventCache()
+       assert.Equal(t, cache.IsStarted(), false, "EventCache should not be 
started when constructed")
+       // adding event to stopped cache does not cause panic
+       cache.AddEvent(nil)
+       cache.StartService()
+       // add an event
+       cache.AddEvent(nil)
+       assert.Equal(t, cache.IsStarted(), true, "EventCache should have been 
started")
+       cache.Stop()
+       // adding event to stopped cache does not cause panic
+       cache.AddEvent(nil)
+       assert.Equal(t, cache.IsStarted(), false, "EventCache should have been 
stopped")
+}
+
+func TestSingleEvent(t *testing.T) {
+       cache := GetEventCache()
+       store := cache.GetEventStore()
+
+       cache.StartService()
+
+       event := si.EventRecord{
+               Type:     si.EventRecord_REQUEST,
+               ObjectID: "alloc1",
+               GroupID:  "app1",
+               Reason:   "reason",
+               Message:  "message",
+       }
+       cache.AddEvent(&event)
+
+       // wait for events to be processed
+       time.Sleep(1 * time.Millisecond)
+
+       records := store.CollectEvents()
+       if records == nil {
+               t.Fatal("collecting eventChannel should return something")
+       }
+       assert.Equal(t, len(records), 1)
+       record := records[0]
+       assert.Equal(t, record.Type, si.EventRecord_REQUEST)
+       assert.Equal(t, record.ObjectID, "alloc1")
+       assert.Equal(t, record.GroupID, "app1")
+       assert.Equal(t, record.Message, "message")
+       assert.Equal(t, record.Reason, "reason")
+}
+
+func TestMultipleEvents(t *testing.T) {
+       cache := GetEventCache()
+       store := cache.GetEventStore()
+
+       cache.StartService()
+
+       event1 := si.EventRecord{
+               Type:     si.EventRecord_REQUEST,
+               ObjectID: "alloc1",
+               GroupID:  "app1",
+               Reason:   "reason1",
+               Message:  "message1",
+       }
+       event2 := si.EventRecord{
+               Type:     si.EventRecord_REQUEST,
+               ObjectID: "alloc1",
+               GroupID:  "app1",
+               Reason:   "reason2",
+               Message:  "message2",
+       }
+       event3 := si.EventRecord{
+               Type:     si.EventRecord_REQUEST,
+               ObjectID: "alloc2",
+               GroupID:  "app2",
+               Reason:   "reason3",
+               Message:  "message3",
+       }
+       cache.AddEvent(&event1)
+       cache.AddEvent(&event2)
+       cache.AddEvent(&event3)
+
+       // wait for cache to process the event
+       time.Sleep(1 * time.Millisecond)

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to