Skip to content

Commit

Permalink
#163 Add reinitialize() and destroy() to AbstractFactory (#164)
Browse files Browse the repository at this point in the history
* #163 Savepoint

* #163 Prepare for versioned release

* #163 Prepare for versioned release
  • Loading branch information
docktermj authored Oct 30, 2024
1 parent 0733f4e commit b7b6474
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 842 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-test-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
go: ["1.21"]
os: [macos-13]
os: [macos-latest]

steps:
- name: Checkout repository
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ jobs:

- name: Copy Senzing headers
run: |
mkdir --parents ./szconfig/gohelpers
mkdir --parents ./szconfig/szhelpers
cp /opt/senzing/er/sdk/c/*.h ./szconfig/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szconfig/gohelpers
mkdir --parents ./szconfigmanager/gohelpers
cp /opt/senzing/er/sdk/c/szhelpers/*.h ./szconfig/szhelpers
mkdir --parents ./szconfigmanager/szhelpers
cp /opt/senzing/er/sdk/c/*.h ./szconfigmanager/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szconfigmanager/gohelpers
mkdir --parents ./szdiagnostic/gohelpers
cp /opt/senzing/er/sdk/c/szhelpers/*.h ./szconfigmanager/szhelpers
mkdir --parents ./szdiagnostic/szhelpers
cp /opt/senzing/er/sdk/c/*.h ./szdiagnostic/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szdiagnostic/gohelpers
mkdir --parents ./szengine/gohelpers
cp /opt/senzing/er/sdk/c/szhelpers/*.h ./szdiagnostic/szhelpers
mkdir --parents ./szengine/szhelpers
cp /opt/senzing/er/sdk/c/*.h ./szengine/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szengine/gohelpers
mkdir --parents ./szproduct/gohelpers
cp /opt/senzing/er/sdk/c/szhelpers/*.h ./szengine/szhelpers
mkdir --parents ./szproduct/szhelpers
cp /opt/senzing/er/sdk/c/*.h ./szproduct/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szproduct/gohelpers
cp /opt/senzing/er/sdk/c/szhelpers/*.h ./szproduct/szhelpers
- name: Setup go
uses: actions/setup-go@v5
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning].

-

## [0.8.3] - 2024-10-30

### Changed in 0.8.3

- Moved `Reinitialize()` and `Destroy()` to SzAbstractFactory

## [0.8.2] - 2024-10-01

### Added in 0.8.2
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ require (
github.com/senzing-garage/go-logging v1.5.1
github.com/senzing-garage/go-messaging v1.5.2
github.com/senzing-garage/go-observing v0.3.3
github.com/senzing-garage/sz-sdk-go v0.14.2
github.com/senzing-garage/sz-sdk-go v0.14.3
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ github.com/senzing-garage/go-messaging v1.5.2 h1:lU9W2HV3zKQsDU9Vs7lwe/C/LbHVCMn
github.com/senzing-garage/go-messaging v1.5.2/go.mod h1:iEWGVuDGWjolIkwLqnn9oJS7ifF3aoZjTtI44tf1gWQ=
github.com/senzing-garage/go-observing v0.3.3 h1:AhQYgOG012sDZtWXYcXVAaS5qEoDjlWmPYJDVCUZ/g0=
github.com/senzing-garage/go-observing v0.3.3/go.mod h1:qFUi5Dwb6vmd7izTZGjGbWKUGRHzWzsgbsX3oNSD198=
github.com/senzing-garage/sz-sdk-go v0.14.2 h1:1LksQW0+epSY0DhlxThxrnfeDwgyLPvyqG9NehZmz04=
github.com/senzing-garage/sz-sdk-go v0.14.2/go.mod h1:rj9HH6qo+kW5PsFSRnEIUQqDZBE34gZjQGsDvAxw6dI=
github.com/senzing-garage/sz-sdk-go v0.14.3 h1:vcTJDn84bTGuFt2kWw8jDf4FfgUSePB+UJg3C2cPIBk=
github.com/senzing-garage/sz-sdk-go v0.14.3/go.mod h1:rj9HH6qo+kW5PsFSRnEIUQqDZBE34gZjQGsDvAxw6dI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f h1:cUMEy+8oS78BWIH9OWazBkzbr090Od9tWBNtZHkOhf0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
35 changes: 8 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ func main() {

szConfig, err := getSzConfig(ctx)
failOnError(5002, err)
defer func() { handleError(szConfig.Destroy(ctx)) }()

szConfigManager, err := getSzConfigManager(ctx)
failOnError(5003, err)
defer func() { handleError(szConfigManager.Destroy(ctx)) }()

// Persist the Senzing configuration to the Senzing repository.

Expand All @@ -88,11 +86,9 @@ func main() {

szEngine, err := getSzEngine(ctx)
failOnError(5005, err)
defer func() { handleError(szEngine.Destroy(ctx)) }()

szProduct, err := getSzProduct(ctx)
failOnError(5006, err)
defer func() { handleError(szProduct.Destroy(ctx)) }()

// Demonstrate tests.

Expand Down Expand Up @@ -189,44 +185,29 @@ func getLogger(ctx context.Context) (logging.Logging, error) {
}

func getSzConfig(ctx context.Context) (senzing.SzConfig, error) {
var err error
_ = ctx
result := szconfig.Szconfig{}
instanceName := "Test name"
settings := "{}"
verboseLogging := senzing.SzNoLogging
err := result.Initialize(ctx, instanceName, settings, verboseLogging)
return &result, err
}

func getSzConfigManager(ctx context.Context) (senzing.SzConfigManager, error) {
var err error
_ = ctx
result := szconfigmanager.Szconfigmanager{}
instanceName := "Test name"
settings := "{}"
verboseLogging := senzing.SzNoLogging
err := result.Initialize(ctx, instanceName, settings, verboseLogging)
return &result, err
}

func getSzEngine(ctx context.Context) (senzing.SzEngine, error) {
var err error
_ = ctx
result := szengine.Szengine{}
instanceName := "Test name"
settings := "{}"
verboseLogging := senzing.SzNoLogging
configID := senzing.SzInitializeWithDefaultConfiguration
err := result.Initialize(ctx, instanceName, settings, configID, verboseLogging)
return &result, err
}

func getSzProduct(ctx context.Context) (senzing.SzProduct, error) {
var err error
_ = ctx
result := szproduct.Szproduct{}
instanceName := "Test name"
settings := "{}"
verboseLogging := senzing.SzNoLogging
err := result.Initialize(ctx, instanceName, settings, verboseLogging)
return &result, err
}

func handleError(err error) {
if err != nil {
panic(err)
}
}
27 changes: 27 additions & 0 deletions szabstractfactory/szabstractfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,30 @@ func (factory *Szabstractfactory) CreateSzProduct(ctx context.Context) (senzing.
result := &szproduct.Szproduct{}
return result, nil
}

/*
Method Destroy will destroy and perform cleanup for the Senzing objects created by the AbstractFactory.
It should be called after all other calls are complete.
Input
- ctx: A context to control lifecycle.
*/
func (factory *Szabstractfactory) Destroy(ctx context.Context) error {
var err error
_ = ctx
return err
}

/*
Method Reinitialize re-initializes the Senzing objects created by the AbstractFactory with a specific Senzing configuration JSON document identifier.
Input
- ctx: A context to control lifecycle.
- configID: The Senzing configuration JSON document identifier used for the initialization.
*/
func (factory *Szabstractfactory) Reinitialize(ctx context.Context, configID int64) error {
var err error
_ = ctx
_ = configID
return err
}
10 changes: 5 additions & 5 deletions szabstractfactory/szabstractfactory_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ExampleSzabstractfactory_CreateSzConfig() {
if err != nil {
fmt.Println(err)
}
defer func() { handleError(szConfig.Destroy(ctx)) }()
_ = szConfig // szConfig can now be used.
// Output:
}

Expand All @@ -33,7 +33,7 @@ func ExampleSzabstractfactory_CreateSzConfigManager() {
if err != nil {
fmt.Println(err)
}
defer func() { handleError(szConfigManager.Destroy(ctx)) }()
_ = szConfigManager // szConfigManager can now be used.
// Output:
}

Expand All @@ -45,7 +45,7 @@ func ExampleSzabstractfactory_CreateSzDiagnostic() {
if err != nil {
fmt.Println(err)
}
defer func() { handleError(szDiagnostic.Destroy(ctx)) }()
_ = szDiagnostic // szDiagnostic can now be used.
// Output:
}

Expand All @@ -57,7 +57,7 @@ func ExampleSzabstractfactory_CreateSzEngine() {
if err != nil {
fmt.Println(err)
}
defer func() { handleError(szEngine.Destroy(ctx)) }()
_ = szEngine // szEngine can now be used.
// Output:
}

Expand All @@ -69,7 +69,7 @@ func ExampleSzabstractfactory_CreateSzProduct() {
if err != nil {
fmt.Println(err)
}
defer func() { handleError(szProduct.Destroy(ctx)) }()
_ = szProduct // szProduct can now be used.
// Output:
}

Expand Down
28 changes: 23 additions & 5 deletions szabstractfactory/szabstractfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
func TestSzAbstractFactory_CreateSzConfig(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfig, err := szAbstractFactory.CreateSzConfig(ctx)
require.NoError(test, err)
defer func() { handleError(szConfig.Destroy(ctx)) }()
configHandle, err := szConfig.CreateConfig(ctx)
require.NoError(test, err)
dataSources, err := szConfig.GetDataSources(ctx, configHandle)
Expand All @@ -38,9 +38,9 @@ func TestSzAbstractFactory_CreateSzConfig(test *testing.T) {
func TestSzAbstractFactory_CreateSzConfigManager(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfigManager, err := szAbstractFactory.CreateSzConfigManager(ctx)
require.NoError(test, err)
defer func() { handleError(szConfigManager.Destroy(ctx)) }()
configList, err := szConfigManager.GetConfigs(ctx)
require.NoError(test, err)
printActual(test, configList)
Expand All @@ -49,9 +49,9 @@ func TestSzAbstractFactory_CreateSzConfigManager(test *testing.T) {
func TestSzAbstractFactory_CreateSzDiagnostic(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szDiagnostic, err := szAbstractFactory.CreateSzDiagnostic(ctx)
require.NoError(test, err)
defer func() { handleError(szDiagnostic.Destroy(ctx)) }()
result, err := szDiagnostic.CheckDatastorePerformance(ctx, 1)
require.NoError(test, err)
printActual(test, result)
Expand All @@ -60,9 +60,9 @@ func TestSzAbstractFactory_CreateSzDiagnostic(test *testing.T) {
func TestSzAbstractFactory_CreateSzEngine(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szEngine, err := szAbstractFactory.CreateSzEngine(ctx)
require.NoError(test, err)
defer func() { handleError(szEngine.Destroy(ctx)) }()
stats, err := szEngine.GetStats(ctx)
require.NoError(test, err)
printActual(test, stats)
Expand All @@ -71,14 +71,32 @@ func TestSzAbstractFactory_CreateSzEngine(test *testing.T) {
func TestSzAbstractFactory_CreateSzProduct(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szProduct, err := szAbstractFactory.CreateSzProduct(ctx)
require.NoError(test, err)
defer func() { handleError(szProduct.Destroy(ctx)) }()
version, err := szProduct.GetVersion(ctx)
require.NoError(test, err)
printActual(test, version)
}

func TestSzAbstractFactory_Destroy(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
}

func TestSzAbstractFactory_Reinitialize(test *testing.T) {
ctx := context.TODO()
szAbstractFactory := getTestObject(ctx, test)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfigManager, err := szAbstractFactory.CreateSzConfigManager(ctx)
require.NoError(test, err)
configID, err := szConfigManager.GetDefaultConfigID(ctx)
require.NoError(test, err)
err = szAbstractFactory.Reinitialize(ctx, configID)
require.NoError(test, err)
}

// ----------------------------------------------------------------------------
// Internal functions
// ----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit b7b6474

Please sign in to comment.