github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/disttae/engine_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package disttae
    16  
    17  /*
    18  type testTxnOperator struct {
    19  	meta txn.TxnMeta
    20  }
    21  
    22  func TestCache(t *testing.T) {
    23  	db := new(DB)
    24  	ctx := context.Background()
    25  	ts := newTimestamp(rand.Int63())
    26  	_ = db.Update(ctx, nil, 0, 0, ts)
    27  	_ = db.BlockList(ctx, nil, 0, 0, ts, nil)
    28  	_, _ = db.NewReader(ctx, 0, nil, nil, 0, 0, ts, nil)
    29  }
    30  
    31  func TestEngine(t *testing.T) {
    32  	ctx := context.Background()
    33  	getClusterDetails := func() (details logservice.ClusterDetails, err error) {
    34  		return
    35  	}
    36  	txnOp := newTestTxnOperator()
    37  	m := mheap.New(guest.New(1<<20, host.New(1<<20)))
    38  	e := New(m, ctx, nil, getClusterDetails)
    39  	err := e.New(ctx, txnOp)
    40  	require.NoError(t, err)
    41  	err = e.Create(ctx, "test", txnOp)
    42  	require.NoError(t, err)
    43  	err = e.Delete(ctx, "test", txnOp)
    44  	require.NoError(t, err)
    45  	err = e.Commit(ctx, txnOp)
    46  	require.NoError(t, err)
    47  	err = e.Rollback(ctx, txnOp)
    48  	require.True(t, moerr.IsMoErrCode(err, moerr.ErrTxnClosed))
    49  	_, err = e.Nodes()
    50  	require.NoError(t, err)
    51  	hints := e.Hints()
    52  	require.Equal(t, time.Minute*5, hints.CommitOrRollbackTimeout)
    53  }
    54  
    55  func TestTransaction(t *testing.T) {
    56  	txn := &Transaction{
    57  		readOnly: false,
    58  		meta:     newTxnMeta(rand.Int63()),
    59  		fileMap:  make(map[string]uint64),
    60  	}
    61  	txn.writes = append(txn.writes, make([]Entry, 0, 1))
    62  	ro := txn.ReadOnly()
    63  	require.Equal(t, false, ro)
    64  	err := txn.WriteBatch(INSERT, 0, 0, "test", "test", new(batch.Batch))
    65  	require.NoError(t, err)
    66  	txn.IncStatementId()
    67  	txn.RegisterFile("test")
    68  	err = txn.WriteFile(DELETE, 0, 0, "test", "test", "test")
    69  	require.NoError(t, err)
    70  	ctx := context.TODO()
    71  
    72  	bm := makeBlockMetaForTest()
    73  	_, err = blockWrite(ctx, bm, testutil.NewBatch([]types.Type{
    74  		types.T_int64.ToType(),
    75  		types.T_int64.ToType(),
    76  		types.T_int64.ToType(),
    77  		types.T_int64.ToType(),
    78  	}, true, 20, testutil.NewMheap()), testutil.NewFS())
    79  	if err != nil {
    80  		t.Fatalf("err: %v", err)
    81  	}
    82  	// fmt.Printf("%v", blks)
    83  
    84  	_, _ = txn.getRow(ctx, 0, 0, nil, nil, makeFunctionExprForTest(">", []*plan.Expr{
    85  		makeColExprForTest(0, types.T_int64),
    86  		plan2.MakePlan2Int64ConstExprWithType(20),
    87  	}), nil)
    88  
    89  	_, _ = txn.getRows(ctx, 0, 0, nil, nil, makeFunctionExprForTest(">", []*plan.Expr{
    90  		makeColExprForTest(0, types.T_int64),
    91  		plan2.MakePlan2Int64ConstExprWithType(20),
    92  	}), nil)
    93  
    94  }
    95  
    96  func TestTable(t *testing.T) {
    97  	tbl := new(table)
    98  	ctx := context.TODO()
    99  	_, _ = tbl.Rows(ctx)
   100  	_, _ = tbl.Size(ctx, "test")
   101  	_, _ = tbl.Ranges(ctx)
   102  	_, _ = tbl.TableDefs(ctx)
   103  	_, _ = tbl.GetPrimaryKeys(ctx)
   104  	_, _ = tbl.GetHideKeys(ctx)
   105  	_ = tbl.Write(ctx, nil)
   106  	_ = tbl.Update(ctx, nil)
   107  	_ = tbl.Delete(ctx, nil, "test")
   108  	_, _ = tbl.Truncate(ctx)
   109  	_ = tbl.AddTableDef(ctx, nil)
   110  	_ = tbl.DelTableDef(ctx, nil)
   111  	_ = tbl.GetTableID(ctx)
   112  	_, _ = tbl.NewReader(ctx, 0, nil, nil)
   113  }
   114  
   115  func TestTools(t *testing.T) {
   116  	_ = genCreateTableTuple("test")
   117  	_ = genCreateColumnTuple(nil)
   118  	_ = genDropTableTuple("test")
   119  	_ = genDropColumnsTuple("test")
   120  	_ = genDatabaseIdExpr("test")
   121  	_ = genTableIdExpr(0, "test")
   122  }
   123  
   124  func newTestTxnOperator() *testTxnOperator {
   125  	return &testTxnOperator{
   126  		meta: newTxnMeta(rand.Int63()),
   127  	}
   128  }
   129  
   130  func (op *testTxnOperator) Txn() txn.TxnMeta {
   131  	return op.meta
   132  }
   133  
   134  func (op *testTxnOperator) Snapshot() ([]byte, error) {
   135  	return nil, nil
   136  }
   137  
   138  func (op *testTxnOperator) ApplySnapshot(data []byte) error {
   139  	return nil
   140  }
   141  
   142  func (op *testTxnOperator) Read(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error) {
   143  	return nil, nil
   144  }
   145  
   146  func (op *testTxnOperator) Write(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error) {
   147  	return nil, nil
   148  }
   149  
   150  func (op *testTxnOperator) WriteAndCommit(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error) {
   151  	return nil, nil
   152  }
   153  
   154  func (op *testTxnOperator) Commit(ctx context.Context) error {
   155  	return nil
   156  }
   157  
   158  func (op *testTxnOperator) Rollback(ctx context.Context) error {
   159  	return nil
   160  }
   161  
   162  func newTimestamp(v int64) timestamp.Timestamp {
   163  	return timestamp.Timestamp{PhysicalTime: v}
   164  }
   165  
   166  func newTxnMeta(snapshotTS int64) txn.TxnMeta {
   167  	id := uuid.New()
   168  	return txn.TxnMeta{
   169  		ID:         id[:],
   170  		Status:     txn.TxnStatus_Active,
   171  		SnapshotTS: newTimestamp(snapshotTS),
   172  	}
   173  }
   174  */