@@ -663,9 +663,11 @@ func TestActivityLog_availableLogs(t *testing.T) {
663
663
}
664
664
}
665
665
666
- // TestActivityLog_MultipleFragmentsAndSegments adds 4000 clients to a fragment and saves it and reads it. The test then
667
- // adds 4000 more clients and calls receivedFragment with 200 more entities. The current segment is saved to storage and
668
- // read back. The test verifies that there are 5000 clients in the first segment index, then the rest in the second index.
666
+ // TestActivityLog_MultipleFragmentsAndSegments adds 4000 clients to a fragment
667
+ // and saves it and reads it. The test then adds 4000 more clients and calls
668
+ // receivedFragment with 200 more entities. The current segment is saved to
669
+ // storage and read back. The test verifies that there are ActivitySegmentClientCapacity clients in the
670
+ // first and second segment index, then the rest in the third index.
669
671
func TestActivityLog_MultipleFragmentsAndSegments (t * testing.T ) {
670
672
core , _ , _ := TestCoreUnsealed (t )
671
673
a := core .activityLog
@@ -685,14 +687,15 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
685
687
startTimestamp := a .GetStartTimestamp ()
686
688
path0 := fmt .Sprintf ("sys/counters/activity/log/entity/%d/0" , startTimestamp )
687
689
path1 := fmt .Sprintf ("sys/counters/activity/log/entity/%d/1" , startTimestamp )
690
+ path2 := fmt .Sprintf ("sys/counters/activity/log/entity/%d/2" , startTimestamp )
688
691
tokenPath := fmt .Sprintf ("sys/counters/activity/log/directtokens/%d/0" , startTimestamp )
689
692
690
693
genID := func (i int ) string {
691
694
return fmt .Sprintf ("11111111-1111-1111-1111-%012d" , i )
692
695
}
693
696
ts := time .Now ().Unix ()
694
697
695
- // First 4000 should fit in one segment
698
+ // First ActivitySegmentClientCapacity should fit in one segment
696
699
for i := 0 ; i < 4000 ; i ++ {
697
700
a .AddEntityToFragment (genID (i ), "root" , ts )
698
701
}
@@ -705,7 +708,7 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
705
708
default :
706
709
}
707
710
708
- // Save incomplete segment
711
+ // Save segment
709
712
err := a .saveCurrentSegmentToStorage (context .Background (), false )
710
713
if err != nil {
711
714
t .Fatalf ("got error writing entities to storage: %v" , err )
@@ -717,8 +720,8 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
717
720
if err != nil {
718
721
t .Fatalf ("could not unmarshal protobuf: %v" , err )
719
722
}
720
- if len (entityLog0 .Clients ) != 4000 {
721
- t .Fatalf ("unexpected entity length. Expected %d, got %d" , 4000 , len (entityLog0 .Clients ))
723
+ if len (entityLog0 .Clients ) != ActivitySegmentClientCapacity {
724
+ t .Fatalf ("unexpected entity length. Expected %d, got %d" , ActivitySegmentClientCapacity , len (entityLog0 .Clients ))
722
725
}
723
726
724
727
// 4000 more local entities
@@ -778,17 +781,17 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
778
781
}
779
782
780
783
seqNum := a .GetEntitySequenceNumber ()
781
- if seqNum != 1 {
782
- t .Fatalf ("expected sequence number 1 , got %v" , seqNum )
784
+ if seqNum != 2 {
785
+ t .Fatalf ("expected sequence number 2 , got %v" , seqNum )
783
786
}
784
787
785
788
protoSegment0 = readSegmentFromStorage (t , core , path0 )
786
789
err = proto .Unmarshal (protoSegment0 .Value , & entityLog0 )
787
790
if err != nil {
788
791
t .Fatalf ("could not unmarshal protobuf: %v" , err )
789
792
}
790
- if len (entityLog0 .Clients ) != activitySegmentClientCapacity {
791
- t .Fatalf ("unexpected client length. Expected %d, got %d" , activitySegmentClientCapacity ,
793
+ if len (entityLog0 .Clients ) != ActivitySegmentClientCapacity {
794
+ t .Fatalf ("unexpected client length. Expected %d, got %d" , ActivitySegmentClientCapacity ,
792
795
len (entityLog0 .Clients ))
793
796
}
794
797
@@ -798,8 +801,19 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
798
801
if err != nil {
799
802
t .Fatalf ("could not unmarshal protobuf: %v" , err )
800
803
}
801
- expectedCount := 8100 - activitySegmentClientCapacity
802
- if len (entityLog1 .Clients ) != expectedCount {
804
+ if len (entityLog1 .Clients ) != ActivitySegmentClientCapacity {
805
+ t .Fatalf ("unexpected entity length. Expected %d, got %d" , ActivitySegmentClientCapacity ,
806
+ len (entityLog1 .Clients ))
807
+ }
808
+
809
+ protoSegment2 := readSegmentFromStorage (t , core , path2 )
810
+ entityLog2 := activity.EntityActivityLog {}
811
+ err = proto .Unmarshal (protoSegment2 .Value , & entityLog2 )
812
+ if err != nil {
813
+ t .Fatalf ("could not unmarshal protobuf: %v" , err )
814
+ }
815
+ expectedCount := 8100 - (ActivitySegmentClientCapacity * 2 )
816
+ if len (entityLog2 .Clients ) != expectedCount {
803
817
t .Fatalf ("unexpected entity length. Expected %d, got %d" , expectedCount ,
804
818
len (entityLog1 .Clients ))
805
819
}
@@ -811,6 +825,9 @@ func TestActivityLog_MultipleFragmentsAndSegments(t *testing.T) {
811
825
for _ , e := range entityLog1 .Clients {
812
826
entityPresent [e .ClientID ] = struct {}{}
813
827
}
828
+ for _ , e := range entityLog2 .Clients {
829
+ entityPresent [e .ClientID ] = struct {}{}
830
+ }
814
831
for i := 0 ; i < 8100 ; i ++ {
815
832
expectedID := genID (i )
816
833
if _ , present := entityPresent [expectedID ]; ! present {
0 commit comments