TransactionsTest (failed)

apache_commons_compress
Terekhin Alexander 5 years ago
parent 7afbe9ef92
commit a8b29ac936
  1. 2
      src/main/java/me/bearns/fias/service/FiasUpdater.java
  2. 2
      src/main/resources/db/changelog/001_AddrObj.yaml
  3. 4
      src/main/resources/db/changelog/002_House.yaml
  4. 4
      src/main/resources/db/changelog/db.changelog-master.yaml
  5. 59
      src/test/java/me/bearns/fias/TransactionsTest.java

@ -10,6 +10,7 @@ import me.bearns.fias.util.RegionFilter;
import me.bearns.fias.util.UnmarshallerParameters; import me.bearns.fias.util.UnmarshallerParameters;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -84,6 +85,7 @@ public class FiasUpdater implements Updater {
} }
//transaction from here //transaction from here
@Transactional
private void processUpdates(List<FiasVersion> updates, boolean reloadFlag) throws CommonException { private void processUpdates(List<FiasVersion> updates, boolean reloadFlag) throws CommonException {
if(reloadFlag) { if(reloadFlag) {

@ -14,7 +14,7 @@ databaseChangeLog:
nullable: false nullable: false
- column: - column:
name: aoguid name: aoguid
type: uuod type: uuid
- column: - column:
name: parentguid name: parentguid
type: uuid type: uuid

@ -14,10 +14,10 @@ databaseChangeLog:
nullable: false nullable: false
- column: - column:
name: aoguid name: aoguid
type: uuod type: uuid
- column: - column:
name: houseguid name: houseguid
type: uuod type: uuid
- column: - column:
name: buildnum name: buildnum
type: varchar(255) type: varchar(255)

@ -1,6 +1,10 @@
databaseChangeLog: databaseChangeLog:
- include: - include:
- file: "000_initial_schema.yaml" - file: "000_initial_schema.yaml"
- relativeToChangelogFile: "true"
- include:
- file: "001_AddrObj.yaml" - file: "001_AddrObj.yaml"
- relativeToChangelogFile: "true"
- include:
- file: "002_House.yaml" - file: "002_House.yaml"
- relativeToChangelogFile: "true" - relativeToChangelogFile: "true"

@ -0,0 +1,59 @@
package me.bearns.fias;
import me.bearns.fias.domain.FiasVersion;
import me.bearns.fias.repository.FiasVersionRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.springframework.transaction.annotation.Isolation.READ_COMMITTED;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TransactionsTest {
private static final long FIRST = 1L;
private static final long NEXT = 2L;
@Autowired
private FiasVersionRepository repository;
@Before
public void before(){
final FiasVersion version = new FiasVersion(FIRST, null, null, null);
repository.save(version);
try {
addNext();
} catch (Exception e) {
//just as planed
e.printStackTrace();
}
}
@Test
public void transactionTest(){
final List<FiasVersion> versions = repository.findAll();
versions.stream().map(FiasVersion::getVersionId).forEach(System.out::println);
assert versions.stream().mapToLong(FiasVersion::getVersionId).anyMatch(v -> FIRST == v);
assert versions.stream().mapToLong(FiasVersion::getVersionId).noneMatch(v -> NEXT == v);
}
@Transactional
public void addNext() throws Exception {
final FiasVersion nextVersion = new FiasVersion(NEXT, null, null, null);
repository.save(nextVersion);
throw new Exception("test");
}
}
Loading…
Cancel
Save