You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by se...@apache.org on 2017/12/26 11:13:37 UTC
[incubator-servicecomb-saga] branch SCB-97_alpha_omega_bonding
updated: SCB-97 ensured events are persisted
This is an automated email from the ASF dual-hosted git repository.
seanyinx pushed a commit to branch SCB-97_alpha_omega_bonding
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
The following commit(s) were added to refs/heads/SCB-97_alpha_omega_bonding by this push:
new 51adc69 SCB-97 ensured events are persisted
51adc69 is described below
commit 51adc69c8d8bdd00a5bdacc304fdb848e7670430
Author: seanyinx <se...@huawei.com>
AuthorDate: Tue Dec 26 19:13:25 2017 +0800
SCB-97 ensured events are persisted
Signed-off-by: seanyinx <se...@huawei.com>
---
integration-tests/pack-tests/pom.xml | 13 ++++++
.../saga/integration/pack/tests/PackIT.java | 13 +++++-
.../integration/pack/tests/TxEventEnvelope.java | 49 ++++++++++++++++++++++
.../pack/tests/TxEventEnvelopeRepository.java | 26 ++++++++++++
.../pack-tests/src/test/resources/application.yaml | 27 ++++++++++++
5 files changed, 127 insertions(+), 1 deletion(-)
diff --git a/integration-tests/pack-tests/pom.xml b/integration-tests/pack-tests/pom.xml
index 41a40d8..4dea6c3 100644
--- a/integration-tests/pack-tests/pom.xml
+++ b/integration-tests/pack-tests/pom.xml
@@ -76,6 +76,16 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
@@ -200,6 +210,9 @@
<alpha.cluster.address>
${docker.hostname}:${alpha.port}
</alpha.cluster.address>
+ <spring.datasource.url>
+ jdbc:mysql://${docker.hostname}:${mysql.port}/saga?useSSL=false
+ </spring.datasource.url>
</systemPropertyVariables>
<argLine>${jacoco.failsafe.argLine}</argLine>
</configuration>
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
index 3c1d0eb..b32eeb6 100644
--- a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpStatus.OK;
+import java.util.List;
import java.util.UUID;
import org.junit.Test;
@@ -41,18 +42,22 @@ import io.servicecomb.saga.omega.context.OmegaContext;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GreetingApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class PackIT {
+ private final String globalTxId = UUID.randomUUID().toString();
+
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private OmegaContext omegaContext;
+ @Autowired
+ private TxEventEnvelopeRepository repository;
@Test
public void updatesTxStateToAlpha() throws Exception {
HttpHeaders headers = new HttpHeaders();
- headers.set(GLOBAL_TX_ID_KEY, UUID.randomUUID().toString());
+ headers.set(GLOBAL_TX_ID_KEY, globalTxId);
ResponseEntity<String> entity = restTemplate.exchange("/greet?name={name}",
GET,
@@ -62,5 +67,11 @@ public class PackIT {
assertThat(entity.getStatusCode(), is(OK));
assertThat(entity.getBody(), is("Greetings, mike"));
+
+ List<TxEventEnvelope> envelopes = repository.findByGlobalTxIdOrderByCreationTime(globalTxId);
+
+ assertThat(envelopes.size(), is(2));
+ assertThat(envelopes.get(0).type(), is("TxStartedEvent"));
+ assertThat(envelopes.get(1).type(), is("TxEndedEvent"));
}
}
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java
new file mode 100644
index 0000000..1ff04e9
--- /dev/null
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java
@@ -0,0 +1,49 @@
+/*
+ * 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
+ *
+ * http://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 io.servicecomb.saga.integration.pack.tests;
+
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+class TxEventEnvelope {
+ @Id
+ @GeneratedValue
+ private long surrogateId;
+
+ private Date creationTime;
+ private String globalTxId;
+ private String localTxId;
+ private String parentTxId;
+ private String type;
+ private byte[] payloads;
+
+ private TxEventEnvelope() {
+ }
+
+ String type() {
+ return type;
+ }
+
+ public byte[] payloads() {
+ return payloads;
+ }
+}
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelopeRepository.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelopeRepository.java
new file mode 100644
index 0000000..7c88c2b
--- /dev/null
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelopeRepository.java
@@ -0,0 +1,26 @@
+/*
+ * 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
+ *
+ * http://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 io.servicecomb.saga.integration.pack.tests;
+
+import java.util.List;
+
+import org.springframework.data.repository.CrudRepository;
+
+interface TxEventEnvelopeRepository extends CrudRepository<TxEventEnvelope, Long> {
+ List<TxEventEnvelope> findByGlobalTxIdOrderByCreationTime(String globalTxId);
+}
diff --git a/integration-tests/pack-tests/src/test/resources/application.yaml b/integration-tests/pack-tests/src/test/resources/application.yaml
new file mode 100644
index 0000000..a7ed531
--- /dev/null
+++ b/integration-tests/pack-tests/src/test/resources/application.yaml
@@ -0,0 +1,27 @@
+## ---------------------------------------------------------------------------
+## 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
+##
+## http://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.
+## ---------------------------------------------------------------------------
+spring:
+ datasource:
+ username: saga
+ password: password
+ driver-class-name: com.mysql.jdbc.Driver
+ jpa:
+ properties:
+ hibernate:
+ dialect: org.hibernate.dialect.MySQL5Dialect
+ hibernate:
+ ddl-auto: none
--
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].