19
19
20
20
import org .apache .seatunnel .e2e .common .TestResource ;
21
21
import org .apache .seatunnel .e2e .common .TestSuiteBase ;
22
+ import org .apache .seatunnel .e2e .common .container .EngineType ;
22
23
import org .apache .seatunnel .e2e .common .container .TestContainer ;
24
+ import org .apache .seatunnel .e2e .common .junit .DisabledOnContainer ;
23
25
24
- import org .apache .hadoop .conf .Configuration ;
25
26
import org .apache .hadoop .hbase .Cell ;
26
27
import org .apache .hadoop .hbase .CellUtil ;
27
- import org .apache .hadoop .hbase .HBaseConfiguration ;
28
28
import org .apache .hadoop .hbase .TableName ;
29
29
import org .apache .hadoop .hbase .client .Admin ;
30
- import org .apache .hadoop .hbase .client .ColumnFamilyDescriptor ;
31
- import org .apache .hadoop .hbase .client .ColumnFamilyDescriptorBuilder ;
32
30
import org .apache .hadoop .hbase .client .Connection ;
33
- import org .apache .hadoop .hbase .client .ConnectionFactory ;
31
+ import org .apache .hadoop .hbase .client .Delete ;
34
32
import org .apache .hadoop .hbase .client .Result ;
35
33
import org .apache .hadoop .hbase .client .ResultScanner ;
36
34
import org .apache .hadoop .hbase .client .Scan ;
37
35
import org .apache .hadoop .hbase .client .Table ;
38
- import org .apache .hadoop .hbase .client .TableDescriptor ;
39
- import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
40
- import org .apache .hadoop .hbase .io .compress .Compression ;
41
36
import org .apache .hadoop .hbase .util .Bytes ;
42
37
43
38
import org .junit .jupiter .api .AfterAll ;
44
39
import org .junit .jupiter .api .Assertions ;
45
40
import org .junit .jupiter .api .BeforeAll ;
46
- import org .junit .jupiter .api .Disabled ;
47
41
import org .junit .jupiter .api .TestTemplate ;
48
42
import org .testcontainers .containers .Container ;
49
- import org .testcontainers .containers .GenericContainer ;
50
- import org .testcontainers .containers .output .Slf4jLogConsumer ;
51
- import org .testcontainers .containers .wait .strategy .HostPortWaitStrategy ;
52
- import org .testcontainers .lifecycle .Startables ;
53
- import org .testcontainers .utility .DockerImageName ;
54
- import org .testcontainers .utility .DockerLoggerFactory ;
55
43
56
44
import lombok .extern .slf4j .Slf4j ;
57
45
58
46
import java .io .IOException ;
59
- import java .time .Duration ;
60
47
import java .util .ArrayList ;
48
+ import java .util .Arrays ;
61
49
import java .util .Objects ;
62
- import java .util .stream .Stream ;
63
50
64
51
@ Slf4j
65
- @ Disabled (
66
- "Hbase docker e2e case need user add mapping information of between container id and ip address in hosts file" )
52
+ @ DisabledOnContainer (
53
+ value = {},
54
+ type = {EngineType .SEATUNNEL },
55
+ disabledReason = "The hbase container authentication configuration is incorrect." )
67
56
public class HbaseIT extends TestSuiteBase implements TestResource {
68
57
69
- private static final String IMAGE = "harisekhon/hbase:latest" ;
70
-
71
- private static final int PORT = 2181 ;
72
-
73
- private static final String HOST = "hbase-e2e" ;
74
-
75
58
private static final String TABLE_NAME = "seatunnel_test" ;
76
59
77
60
private static final String FAMILY_NAME = "info" ;
78
61
79
- private final Configuration hbaseConfiguration = HBaseConfiguration .create ();
80
-
81
62
private Connection hbaseConnection ;
82
63
83
64
private Admin admin ;
84
65
85
66
private TableName table ;
86
67
87
- private GenericContainer <?> hbaseContainer ;
68
+ private HbaseCluster hbaseCluster ;
88
69
89
70
@ BeforeAll
90
71
@ Override
91
72
public void startUp () throws Exception {
92
- hbaseContainer =
93
- new GenericContainer <>(DockerImageName .parse (IMAGE ))
94
- .withNetwork (NETWORK )
95
- .withNetworkAliases (HOST )
96
- .withExposedPorts (PORT )
97
- .withLogConsumer (new Slf4jLogConsumer (DockerLoggerFactory .getLogger (IMAGE )))
98
- .waitingFor (
99
- new HostPortWaitStrategy ()
100
- .withStartupTimeout (Duration .ofMinutes (2 )));
101
- Startables .deepStart (Stream .of (hbaseContainer )).join ();
102
- log .info ("Hbase container started" );
103
- this .initialize ();
73
+ hbaseCluster = new HbaseCluster ();
74
+ hbaseConnection = hbaseCluster .startService ();
75
+ // Create table for hbase sink test
76
+ log .info ("initial" );
77
+ hbaseCluster .createTable (TABLE_NAME , Arrays .asList (FAMILY_NAME ));
78
+ table = TableName .valueOf (TABLE_NAME );
104
79
}
105
80
106
81
@ AfterAll
@@ -109,59 +84,37 @@ public void tearDown() throws Exception {
109
84
if (Objects .nonNull (admin )) {
110
85
admin .close ();
111
86
}
112
- if (Objects .nonNull (hbaseConnection )) {
113
- hbaseConnection .close ();
114
- }
115
- if (Objects .nonNull (hbaseContainer )) {
116
- hbaseContainer .close ();
117
- }
118
- }
119
-
120
- private void initialize () throws IOException {
121
- hbaseConfiguration .set ("hbase.zookeeper.quorum" , HOST + ":" + PORT );
122
- hbaseConnection = ConnectionFactory .createConnection (hbaseConfiguration );
123
- admin = hbaseConnection .getAdmin ();
124
- table = TableName .valueOf (TABLE_NAME );
125
- ColumnFamilyDescriptor familyDescriptor =
126
- ColumnFamilyDescriptorBuilder .newBuilder (FAMILY_NAME .getBytes ())
127
- .setCompressionType (Compression .Algorithm .SNAPPY )
128
- .setCompactionCompressionType (Compression .Algorithm .SNAPPY )
129
- .build ();
130
- TableDescriptor tableDescriptor =
131
- TableDescriptorBuilder .newBuilder (table ).setColumnFamily (familyDescriptor ).build ();
132
- admin .createTable (tableDescriptor );
133
- log .info ("Hbase table has been initialized" );
87
+ hbaseCluster .stopService ();
134
88
}
135
89
136
90
@ TestTemplate
137
91
public void testHbaseSink (TestContainer container ) throws IOException , InterruptedException {
138
- Container .ExecResult execResult = container .executeJob ("/fake-to-hbase.conf" );
139
- Assertions .assertEquals (0 , execResult .getExitCode ());
92
+ deleteData (table );
93
+ Container .ExecResult sinkExecResult = container .executeJob ("/fake-to-hbase.conf" );
94
+ Assertions .assertEquals (0 , sinkExecResult .getExitCode ());
140
95
Table hbaseTable = hbaseConnection .getTable (table );
141
96
Scan scan = new Scan ();
142
- ArrayList <Result > results = new ArrayList <>();
143
97
ResultScanner scanner = hbaseTable .getScanner (scan );
98
+ ArrayList <Result > results = new ArrayList <>();
144
99
for (Result result : scanner ) {
145
100
results .add (result );
146
101
}
147
102
Assertions .assertEquals (results .size (), 5 );
148
- }
149
-
150
- @ TestTemplate
151
- public void testHbaseSource (TestContainer container ) throws IOException , InterruptedException {
152
- Container .ExecResult execResult = container .executeJob ("/hbase-to-assert.conf" );
153
- Assertions .assertEquals (0 , execResult .getExitCode ());
103
+ scanner .close ();
104
+ Container .ExecResult sourceExecResult = container .executeJob ("/hbase-to-assert.conf" );
105
+ Assertions .assertEquals (0 , sourceExecResult .getExitCode ());
154
106
}
155
107
156
108
@ TestTemplate
157
109
public void testHbaseSinkWithArray (TestContainer container )
158
110
throws IOException , InterruptedException {
111
+ deleteData (table );
159
112
Container .ExecResult execResult = container .executeJob ("/fake-to-hbase-array.conf" );
160
113
Assertions .assertEquals (0 , execResult .getExitCode ());
161
114
Table hbaseTable = hbaseConnection .getTable (table );
162
115
Scan scan = new Scan ();
163
- ArrayList <Result > results = new ArrayList <>();
164
116
ResultScanner scanner = hbaseTable .getScanner (scan );
117
+ ArrayList <Result > results = new ArrayList <>();
165
118
for (Result result : scanner ) {
166
119
String rowKey = Bytes .toString (result .getRow ());
167
120
for (Cell cell : result .listCells ()) {
@@ -177,5 +130,17 @@ public void testHbaseSinkWithArray(TestContainer container)
177
130
results .add (result );
178
131
}
179
132
Assertions .assertEquals (results .size (), 3 );
133
+ scanner .close ();
134
+ }
135
+
136
+ private void deleteData (TableName table ) throws IOException {
137
+ Table hbaseTable = hbaseConnection .getTable (table );
138
+ Scan scan = new Scan ();
139
+ ResultScanner scanner = hbaseTable .getScanner (scan );
140
+ // Delete the data generated by the test
141
+ for (Result result = scanner .next (); result != null ; result = scanner .next ()) {
142
+ Delete deleteRow = new Delete (result .getRow ());
143
+ hbaseTable .delete (deleteRow );
144
+ }
180
145
}
181
146
}
0 commit comments