tszerszen commented on a change in pull request #13245:
URL: https://github.com/apache/beam/pull/13245#discussion_r517254914



##########
File path: sdks/go/pkg/beam/io/synthetic/source_test.go
##########
@@ -162,6 +164,83 @@ func TestSourceConfig_BuildFromJSON(t *testing.T) {
        }
 }
 
+// TestSourceConfig_NumHotKeys tests that setting the number of hot keys
+// for a synthetic source works correctly.
+func TestSourceConfigBuilder_NumHotKeys(t *testing.T) {
+       tests := []struct {
+               elms    int
+               hotKeys int
+       }{
+               {elms: 15, hotKeys: 2},
+               {elms: 30, hotKeys: 10},
+               {elms: 50, hotKeys: 25},
+       }
+       for _, test := range tests {
+               test := test
+               t.Run(fmt.Sprintf("(elm = %v)", test.hotKeys), func(t 
*testing.T) {
+                       dfn := sourceFn{}
+                       cfg := DefaultSourceConfig()
+                       cfg.NumElements(test.elms)
+                       cfg.HotKeyFraction(1.0)
+                       cfg.NumHotKeys(test.hotKeys)
+
+                       keys, _, err := simulateSourceFn(t, &dfn, cfg.Build())
+                       if err != nil {
+                               t.Errorf("Failure processing sourceFn: %v", err)
+                       }
+
+                       type val struct {
+                               num      int
+                               isHotKey bool
+                       }
+
+                       m := make(map[string]val)

Review comment:
       Thank you for help! 
   
   @kamilwu wrote:
   ```golang
   counter := make(map[byte]int) // no need to convert to string
   ```
   
   I think it should be byte array
   ```golang
   counter := make(map[[]byte]int) 
   ```
   And you can't use byte array in map.
   
   ```golang
   for _, key := range keys {
       counter[key]++
   }
   ```
   You're right. In the last commit I removed the struct and used direct 
counter, also I added support for testing HotKeyFraction. However I'm a bit 
worried that testing HotKeyFraction could be Flaky, what do you think?
   
   




----------------------------------------------------------------
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:
[email protected]


Reply via email to