You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/31 12:54:55 UTC

[plc4x] 01/03: refactor(plc4go/spi): move transaction manager to own package

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 09147a8d953167c37a04eaaf49ecf4819f4b9be1
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 31 13:13:00 2023 +0200

    refactor(plc4go/spi): move transaction manager to own package
---
 .../RequestTransactionManager.go                   |  12 +-
 .../RequestTransactionManager_test.go              |   4 +-
 .../spi/transactions/mock_CompletionFuture_test.go | 132 +++++++++++++++++++++
 .../mock_RequestTransactionManagerOption_test.go   |   2 +-
 .../mock_RequestTransactionManager_test.go         |   2 +-
 .../mock_RequestTransactionRunnable_test.go        |  16 +--
 .../mock_RequestTransaction_test.go                |   2 +-
 plc4go/spi/transactions/mock_requirements.go       |  31 +++++
 8 files changed, 182 insertions(+), 19 deletions(-)

diff --git a/plc4go/spi/RequestTransactionManager.go b/plc4go/spi/transactions/RequestTransactionManager.go
similarity index 97%
rename from plc4go/spi/RequestTransactionManager.go
rename to plc4go/spi/transactions/RequestTransactionManager.go
index cf14625ad6..08865904b1 100644
--- a/plc4go/spi/RequestTransactionManager.go
+++ b/plc4go/spi/transactions/RequestTransactionManager.go
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package spi
+package transactions
 
 import (
 	"container/list"
@@ -42,7 +42,7 @@ func init() {
 	sharedExecutorInstance.Start()
 }
 
-type RequestTransactionRunnable func(transaction RequestTransaction)
+type RequestTransactionRunnable func(RequestTransaction)
 
 // RequestTransaction represents a transaction
 type RequestTransaction interface {
@@ -107,7 +107,7 @@ type requestTransaction struct {
 
 type requestTransactionManager struct {
 	runningRequests []*requestTransaction
-	// How many Transactions are allowed to run at the same time?
+	// How many transactions are allowed to run at the same time?
 	numberOfConcurrentRequests int
 	// Assigns each request a Unique Transaction Id, especially important for failure handling
 	transactionId    int32
@@ -139,12 +139,12 @@ func (r *requestTransactionManager) SetNumberOfConcurrentRequests(numberOfConcur
 }
 
 func (r *requestTransactionManager) submitTransaction(transaction *requestTransaction) {
-	// Add this Request with this transaction i the Worklog
-	// Put Transaction into Worklog
+	// Add this Request with the transaction i the work log
+	// Put Transaction into work log
 	r.workLogMutex.Lock()
 	r.workLog.PushFront(transaction)
 	r.workLogMutex.Unlock()
-	// Try to Process the Worklog
+	// Try to Process the work log
 	r.processWorklog()
 }
 
diff --git a/plc4go/spi/RequestTransactionManager_test.go b/plc4go/spi/transactions/RequestTransactionManager_test.go
similarity index 99%
rename from plc4go/spi/RequestTransactionManager_test.go
rename to plc4go/spi/transactions/RequestTransactionManager_test.go
index 9c364221d1..c46767ece0 100644
--- a/plc4go/spi/RequestTransactionManager_test.go
+++ b/plc4go/spi/transactions/RequestTransactionManager_test.go
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package spi
+package transactions
 
 import (
 	"container/list"
@@ -443,7 +443,7 @@ func Test_requestTransaction_AwaitCompletion(t1 *testing.T) {
 							r := &requestTransaction{}
 							go func() {
 								time.Sleep(100 * time.Millisecond)
-								// We fake a ending transaction like that
+								// We fake an ending transaction like that
 								r.transactionId = 1
 							}()
 							return r
diff --git a/plc4go/spi/transactions/mock_CompletionFuture_test.go b/plc4go/spi/transactions/mock_CompletionFuture_test.go
new file mode 100644
index 0000000000..ec72fc9d8a
--- /dev/null
+++ b/plc4go/spi/transactions/mock_CompletionFuture_test.go
@@ -0,0 +1,132 @@
+/*
+ * 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
+ *
+ *   https://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.
+ */
+
+// Code generated by mockery v2.28.1. DO NOT EDIT.
+
+package transactions
+
+import (
+	context "context"
+
+	mock "github.com/stretchr/testify/mock"
+)
+
+// MockCompletionFuture is an autogenerated mock type for the CompletionFuture type
+type MockCompletionFuture struct {
+	mock.Mock
+}
+
+type MockCompletionFuture_Expecter struct {
+	mock *mock.Mock
+}
+
+func (_m *MockCompletionFuture) EXPECT() *MockCompletionFuture_Expecter {
+	return &MockCompletionFuture_Expecter{mock: &_m.Mock}
+}
+
+// AwaitCompletion provides a mock function with given fields: ctx
+func (_m *MockCompletionFuture) AwaitCompletion(ctx context.Context) error {
+	ret := _m.Called(ctx)
+
+	var r0 error
+	if rf, ok := ret.Get(0).(func(context.Context) error); ok {
+		r0 = rf(ctx)
+	} else {
+		r0 = ret.Error(0)
+	}
+
+	return r0
+}
+
+// MockCompletionFuture_AwaitCompletion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AwaitCompletion'
+type MockCompletionFuture_AwaitCompletion_Call struct {
+	*mock.Call
+}
+
+// AwaitCompletion is a helper method to define mock.On call
+//   - ctx context.Context
+func (_e *MockCompletionFuture_Expecter) AwaitCompletion(ctx interface{}) *MockCompletionFuture_AwaitCompletion_Call {
+	return &MockCompletionFuture_AwaitCompletion_Call{Call: _e.mock.On("AwaitCompletion", ctx)}
+}
+
+func (_c *MockCompletionFuture_AwaitCompletion_Call) Run(run func(ctx context.Context)) *MockCompletionFuture_AwaitCompletion_Call {
+	_c.Call.Run(func(args mock.Arguments) {
+		run(args[0].(context.Context))
+	})
+	return _c
+}
+
+func (_c *MockCompletionFuture_AwaitCompletion_Call) Return(_a0 error) *MockCompletionFuture_AwaitCompletion_Call {
+	_c.Call.Return(_a0)
+	return _c
+}
+
+func (_c *MockCompletionFuture_AwaitCompletion_Call) RunAndReturn(run func(context.Context) error) *MockCompletionFuture_AwaitCompletion_Call {
+	_c.Call.Return(run)
+	return _c
+}
+
+// Cancel provides a mock function with given fields: interrupt, err
+func (_m *MockCompletionFuture) Cancel(interrupt bool, err error) {
+	_m.Called(interrupt, err)
+}
+
+// MockCompletionFuture_Cancel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Cancel'
+type MockCompletionFuture_Cancel_Call struct {
+	*mock.Call
+}
+
+// Cancel is a helper method to define mock.On call
+//   - interrupt bool
+//   - err error
+func (_e *MockCompletionFuture_Expecter) Cancel(interrupt interface{}, err interface{}) *MockCompletionFuture_Cancel_Call {
+	return &MockCompletionFuture_Cancel_Call{Call: _e.mock.On("Cancel", interrupt, err)}
+}
+
+func (_c *MockCompletionFuture_Cancel_Call) Run(run func(interrupt bool, err error)) *MockCompletionFuture_Cancel_Call {
+	_c.Call.Run(func(args mock.Arguments) {
+		run(args[0].(bool), args[1].(error))
+	})
+	return _c
+}
+
+func (_c *MockCompletionFuture_Cancel_Call) Return() *MockCompletionFuture_Cancel_Call {
+	_c.Call.Return()
+	return _c
+}
+
+func (_c *MockCompletionFuture_Cancel_Call) RunAndReturn(run func(bool, error)) *MockCompletionFuture_Cancel_Call {
+	_c.Call.Return(run)
+	return _c
+}
+
+type mockConstructorTestingTNewMockCompletionFuture interface {
+	mock.TestingT
+	Cleanup(func())
+}
+
+// NewMockCompletionFuture creates a new instance of MockCompletionFuture. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+func NewMockCompletionFuture(t mockConstructorTestingTNewMockCompletionFuture) *MockCompletionFuture {
+	mock := &MockCompletionFuture{}
+	mock.Mock.Test(t)
+
+	t.Cleanup(func() { mock.AssertExpectations(t) })
+
+	return mock
+}
diff --git a/plc4go/spi/mock_RequestTransactionManagerOption_test.go b/plc4go/spi/transactions/mock_RequestTransactionManagerOption_test.go
similarity index 99%
rename from plc4go/spi/mock_RequestTransactionManagerOption_test.go
rename to plc4go/spi/transactions/mock_RequestTransactionManagerOption_test.go
index 59a3f73e36..8bea8076f2 100644
--- a/plc4go/spi/mock_RequestTransactionManagerOption_test.go
+++ b/plc4go/spi/transactions/mock_RequestTransactionManagerOption_test.go
@@ -19,7 +19,7 @@
 
 // Code generated by mockery v2.28.1. DO NOT EDIT.
 
-package spi
+package transactions
 
 import mock "github.com/stretchr/testify/mock"
 
diff --git a/plc4go/spi/mock_RequestTransactionManager_test.go b/plc4go/spi/transactions/mock_RequestTransactionManager_test.go
similarity index 99%
rename from plc4go/spi/mock_RequestTransactionManager_test.go
rename to plc4go/spi/transactions/mock_RequestTransactionManager_test.go
index 962439f3fa..f15b138ff3 100644
--- a/plc4go/spi/mock_RequestTransactionManager_test.go
+++ b/plc4go/spi/transactions/mock_RequestTransactionManager_test.go
@@ -19,7 +19,7 @@
 
 // Code generated by mockery v2.28.1. DO NOT EDIT.
 
-package spi
+package transactions
 
 import mock "github.com/stretchr/testify/mock"
 
diff --git a/plc4go/spi/mock_RequestTransactionRunnable_test.go b/plc4go/spi/transactions/mock_RequestTransactionRunnable_test.go
similarity index 85%
rename from plc4go/spi/mock_RequestTransactionRunnable_test.go
rename to plc4go/spi/transactions/mock_RequestTransactionRunnable_test.go
index b621d0cb8e..e80caf3a71 100644
--- a/plc4go/spi/mock_RequestTransactionRunnable_test.go
+++ b/plc4go/spi/transactions/mock_RequestTransactionRunnable_test.go
@@ -19,7 +19,7 @@
 
 // Code generated by mockery v2.28.1. DO NOT EDIT.
 
-package spi
+package transactions
 
 import mock "github.com/stretchr/testify/mock"
 
@@ -36,9 +36,9 @@ func (_m *MockRequestTransactionRunnable) EXPECT() *MockRequestTransactionRunnab
 	return &MockRequestTransactionRunnable_Expecter{mock: &_m.Mock}
 }
 
-// Execute provides a mock function with given fields: transaction
-func (_m *MockRequestTransactionRunnable) Execute(transaction RequestTransaction) {
-	_m.Called(transaction)
+// Execute provides a mock function with given fields: _a0
+func (_m *MockRequestTransactionRunnable) Execute(_a0 RequestTransaction) {
+	_m.Called(_a0)
 }
 
 // MockRequestTransactionRunnable_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute'
@@ -47,12 +47,12 @@ type MockRequestTransactionRunnable_Execute_Call struct {
 }
 
 // Execute is a helper method to define mock.On call
-//   - transaction RequestTransaction
-func (_e *MockRequestTransactionRunnable_Expecter) Execute(transaction interface{}) *MockRequestTransactionRunnable_Execute_Call {
-	return &MockRequestTransactionRunnable_Execute_Call{Call: _e.mock.On("Execute", transaction)}
+//   - _a0 RequestTransaction
+func (_e *MockRequestTransactionRunnable_Expecter) Execute(_a0 interface{}) *MockRequestTransactionRunnable_Execute_Call {
+	return &MockRequestTransactionRunnable_Execute_Call{Call: _e.mock.On("Execute", _a0)}
 }
 
-func (_c *MockRequestTransactionRunnable_Execute_Call) Run(run func(transaction RequestTransaction)) *MockRequestTransactionRunnable_Execute_Call {
+func (_c *MockRequestTransactionRunnable_Execute_Call) Run(run func(_a0 RequestTransaction)) *MockRequestTransactionRunnable_Execute_Call {
 	_c.Call.Run(func(args mock.Arguments) {
 		run(args[0].(RequestTransaction))
 	})
diff --git a/plc4go/spi/mock_RequestTransaction_test.go b/plc4go/spi/transactions/mock_RequestTransaction_test.go
similarity index 99%
rename from plc4go/spi/mock_RequestTransaction_test.go
rename to plc4go/spi/transactions/mock_RequestTransaction_test.go
index 18ed7f3aa9..2c8e24ec20 100644
--- a/plc4go/spi/mock_RequestTransaction_test.go
+++ b/plc4go/spi/transactions/mock_RequestTransaction_test.go
@@ -19,7 +19,7 @@
 
 // Code generated by mockery v2.28.1. DO NOT EDIT.
 
-package spi
+package transactions
 
 import (
 	context "context"
diff --git a/plc4go/spi/transactions/mock_requirements.go b/plc4go/spi/transactions/mock_requirements.go
new file mode 100644
index 0000000000..4feb95b8de
--- /dev/null
+++ b/plc4go/spi/transactions/mock_requirements.go
@@ -0,0 +1,31 @@
+/*
+ * 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
+ *
+ *   https://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 transactions
+
+import (
+	"github.com/apache/plc4x/plc4go/spi/utils"
+)
+
+// Note this file is a Helper for mockery to generate use mocks from other package
+
+// Deprecated: don't use it in productive code
+type CompletionFuture interface {
+	utils.CompletionFuture
+}