mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
217 lines
5.2 KiB
Go
217 lines
5.2 KiB
Go
package tests
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin"
|
|
"go.temporal.io/server/common/shuffle"
|
|
)
|
|
|
|
type (
|
|
historyShardSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
|
|
store sqlplugin.DB
|
|
}
|
|
)
|
|
|
|
const (
|
|
testHistoryShardEncoding = "random encoding"
|
|
)
|
|
|
|
var (
|
|
testHistoryShardData = []byte("random history shard data")
|
|
)
|
|
|
|
func NewHistoryShardSuite(
|
|
t *testing.T,
|
|
store sqlplugin.DB,
|
|
) *historyShardSuite {
|
|
return &historyShardSuite{
|
|
Assertions: require.New(t),
|
|
store: store,
|
|
}
|
|
}
|
|
|
|
func (s *historyShardSuite) SetupSuite() {
|
|
|
|
}
|
|
|
|
func (s *historyShardSuite) TearDownSuite() {
|
|
|
|
}
|
|
|
|
func (s *historyShardSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
}
|
|
|
|
func (s *historyShardSuite) TearDownTest() {
|
|
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsert_Success() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsert_Fail_Duplicate() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
shard = s.newRandomShardRow(shardID, rangeID)
|
|
_, err = s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.Error(err) // TODO persistence layer should do proper error translation
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsertSelect() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
filter := sqlplugin.ShardsFilter{
|
|
ShardID: shardID,
|
|
}
|
|
row, err := s.store.SelectFromShards(newExecutionContext(), filter)
|
|
s.NoError(err)
|
|
s.Equal(&shard, row)
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsertUpdate_Success() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
rangeID += 100
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
shard = s.newRandomShardRow(shardID, rangeID)
|
|
result, err = s.store.UpdateShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err = result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
}
|
|
|
|
func (s *historyShardSuite) TestUpdate_Fail() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.UpdateShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(0, int(rowsAffected))
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsertUpdateSelect() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(1)
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
rangeID += 100
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
shard = s.newRandomShardRow(shardID, rangeID)
|
|
result, err = s.store.UpdateShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err = result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
filter := sqlplugin.ShardsFilter{
|
|
ShardID: shardID,
|
|
}
|
|
row, err := s.store.SelectFromShards(newExecutionContext(), filter)
|
|
s.NoError(err)
|
|
s.Equal(&shard, row)
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsertReadLock() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(rand.Int31())
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
tx, err := s.store.BeginTx(newExecutionContext())
|
|
s.NoError(err)
|
|
filter := sqlplugin.ShardsFilter{
|
|
ShardID: shardID,
|
|
}
|
|
shardRange, err := tx.ReadLockShards(newExecutionContext(), filter)
|
|
s.NoError(err)
|
|
s.Equal(rangeID, shardRange)
|
|
s.NoError(tx.Commit())
|
|
}
|
|
|
|
func (s *historyShardSuite) TestInsertWriteLock() {
|
|
shardID := rand.Int31()
|
|
rangeID := int64(rand.Int31())
|
|
|
|
shard := s.newRandomShardRow(shardID, rangeID)
|
|
result, err := s.store.InsertIntoShards(newExecutionContext(), &shard)
|
|
s.NoError(err)
|
|
rowsAffected, err := result.RowsAffected()
|
|
s.NoError(err)
|
|
s.Equal(1, int(rowsAffected))
|
|
|
|
tx, err := s.store.BeginTx(newExecutionContext())
|
|
s.NoError(err)
|
|
filter := sqlplugin.ShardsFilter{
|
|
ShardID: shardID,
|
|
}
|
|
shardRange, err := tx.WriteLockShards(newExecutionContext(), filter)
|
|
s.NoError(err)
|
|
s.Equal(rangeID, shardRange)
|
|
s.NoError(tx.Commit())
|
|
}
|
|
|
|
func (s *historyShardSuite) newRandomShardRow(
|
|
shardID int32,
|
|
rangeID int64,
|
|
) sqlplugin.ShardsRow {
|
|
return sqlplugin.ShardsRow{
|
|
ShardID: shardID,
|
|
RangeID: rangeID,
|
|
Data: shuffle.Bytes(testHistoryShardData),
|
|
DataEncoding: testHistoryShardEncoding,
|
|
}
|
|
}
|