Skip to content

Commit

Permalink
test: added connection test
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianciutea committed Nov 21, 2021
1 parent 49637c2 commit 042ae62
Show file tree
Hide file tree
Showing 33 changed files with 4,332 additions and 1,186 deletions.
6 changes: 3 additions & 3 deletions build/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ code-gen-deps:
.PHONY : code-gen
code-gen: code-gen-deps
@($(DOCKER_THRIFT) thrift -r --out src/main/java/ --gen java ./commons/nrjmx.thrift)
@($(DOCKER_THRIFT) thrift -r --out src/go/ --gen go:package=protocol ./commons/nrjmx.thrift)
@($(DOCKER_THRIFT) thrift -r --out src/go/ --gen go:package_prefix=github.com/newrelic/nrjmx/,package=nrprotocol ./commons/nrjmx.thrift)

TRACKED_GEN_DIR=src/main/java/protocol \
src/go/protocol
TRACKED_GEN_DIR=src/main/java/prot \
src/go/prot
.PHONY : check-gen-code
check-gen-code: code-gen
@echo "Checking the generated code..." ; \
Expand Down
18 changes: 7 additions & 11 deletions commons/nrjmx.thrift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace java org.newrelic.nrjmx.v2.protocol
namespace java org.newrelic.nrjmx.v2.nrprotocol

struct JMXConfig {
1: string connectionURL
Expand All @@ -19,20 +19,16 @@ enum ValueType {
STRING = 1,
DOUBLE = 2,
INT = 3,
BOOL = 4
}

struct JMXAttributeValue {
1: ValueType valueType,
2: string stringValue,
3: double doubleValue,
4: i64 intValue,
5: bool boolValue
BOOL = 4,
}

struct JMXAttribute {
1: string attribute
2: JMXAttributeValue value
2: ValueType valueType,
3: string stringValue,
4: double doubleValue,
5: i64 intValue,
6: bool boolValue
}

struct LogMessage {
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<version>1.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions src/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/newrelic/nrjmx
go 1.14

require (
github.com/apache/thrift/lib/go/thrift v0.0.1-do-not-use // indirect
github.com/docker/docker v20.10.7+incompatible
github.com/apache/thrift v0.13.0
github.com/docker/docker v20.10.11+incompatible
github.com/docker/go-connections v0.4.0
github.com/newrelic/infra-integrations-sdk v3.7.0+incompatible
github.com/stretchr/testify v1.7.0
github.com/testcontainers/testcontainers-go v0.11.1
github.com/testcontainers/testcontainers-go v0.12.0
)
290 changes: 54 additions & 236 deletions src/go/go.sum

Large diffs are not rendered by default.

109 changes: 0 additions & 109 deletions src/go/jmx_connector_test.go

This file was deleted.

54 changes: 54 additions & 0 deletions src/go/nrjmx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package nrjmx

import (
"context"

"time"

"github.com/apache/thrift/lib/go/thrift"
"github.com/newrelic/nrjmx/nrprotocol"
)

func NewJMXServiceClient(ctx context.Context) (client *JMXClient, err error) {
jmxProcess, err := startJMXProcess(ctx)
if err != nil {
return
}

var protocolFactory thrift.TProtocolFactory
protocolFactory = thrift.NewTCompactProtocolFactory()

var transportFactory thrift.TTransportFactory

transportFactory = thrift.NewTBufferedTransportFactory(8192)

transportFactory = thrift.NewTFramedTransportFactory(transportFactory)

var transport thrift.TTransport

transport = thrift.NewStreamTransport(jmxProcess.Stdout, jmxProcess.Stdin)
transport, err = transportFactory.GetTransport(transport)
if err != nil {
return nil, err
}

iprot := protocolFactory.GetProtocol(transport)
oprot := protocolFactory.GetProtocol(transport)
client = &JMXClient{
JMXService: nrprotocol.NewJMXServiceClient(thrift.NewTStandardClient(iprot, oprot)),
jmxProcess: *jmxProcess,
ctx: ctx,
}
return
}

type JMXClient struct {
nrprotocol.JMXService
jmxProcess jmxProcess
ctx context.Context
}

func (j *JMXClient) Close(timeout time.Duration) error {
j.Disconnect(j.ctx)
return j.jmxProcess.stop(timeout)
}
Loading

0 comments on commit 042ae62

Please sign in to comment.