DATACASS-39 : WIP : Temporarily introducing failing test for CI POC.
This commit is contained in:
@@ -41,15 +41,11 @@ import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.interceptor.DefaultKeyGenerator;
|
||||
import org.springframework.cassandra.core.BoundStatementFactory;
|
||||
import org.springframework.cassandra.core.CachedPreparedStatementCreator;
|
||||
import org.springframework.cassandra.core.CassandraOperations;
|
||||
import org.springframework.cassandra.core.CqlParameter;
|
||||
import org.springframework.cassandra.core.CqlParameterValue;
|
||||
import org.springframework.cassandra.core.HostMapper;
|
||||
import org.springframework.cassandra.core.PreparedStatementBinder;
|
||||
import org.springframework.cassandra.core.PreparedStatementCreatorFactory;
|
||||
import org.springframework.cassandra.core.ResultSetExtractor;
|
||||
import org.springframework.cassandra.core.RingMember;
|
||||
@@ -60,13 +56,10 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.Host;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
/**
|
||||
@@ -196,6 +189,11 @@ public class CassandraOperationsTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failingTest() {
|
||||
assertNotNull(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boundStatementFactoryTest() {
|
||||
|
||||
@@ -209,97 +207,6 @@ public class CassandraOperationsTest {
|
||||
cassandraTemplate.execute(bsf);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void cachedPreparedStatementTest() {
|
||||
|
||||
log.info(echoString("Hello"));
|
||||
log.info(echoString("Hello"));
|
||||
|
||||
String cql = "select * from book where isbn = ?";
|
||||
|
||||
CachedPreparedStatementCreator cpsc = new CachedPreparedStatementCreator(cql);
|
||||
|
||||
Book b = cassandraTemplate.query(cpsc, new PreparedStatementBinder() {
|
||||
|
||||
@Override
|
||||
public BoundStatement bindValues(PreparedStatement ps) throws DriverException {
|
||||
return ps.bind("999999999");
|
||||
}
|
||||
}, new ResultSetExtractor<Book>() {
|
||||
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
Book b = new Book();
|
||||
b.setIsbn(r.getString("isbn"));
|
||||
b.setTitle(r.getString("title"));
|
||||
b.setAuthor(r.getString("author"));
|
||||
b.setPages(r.getInt("pages"));
|
||||
return b;
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(b);
|
||||
|
||||
log.info(b.toString());
|
||||
|
||||
try {
|
||||
DefaultKeyGenerator generator = new DefaultKeyGenerator();
|
||||
|
||||
// TODO Why does method have to be public to work? Options?
|
||||
Object cacheKey = generator.generate(CachedPreparedStatementCreator.class,
|
||||
CachedPreparedStatementCreator.class.getMethod("getCachedPreparedStatement", Session.class, String.class),
|
||||
cassandraTemplate.getSession(), cql);
|
||||
|
||||
log.info("cacheKey -> " + cacheKey);
|
||||
|
||||
// ConcurrentMapCache cache = (ConcurrentMapCache) cacheManager.getCache("sdc-pstmts");
|
||||
// ConcurrentMap cacheMap = cache.getNativeCache();
|
||||
// assertNotNull(cacheMap);
|
||||
// log.info("CacheMap.size() -> " + cacheMap.size());
|
||||
// ValueWrapper vw = cache.get(cacheKey);
|
||||
// PreparedStatement pstmt = (PreparedStatement) vw.get();
|
||||
// assertNotNull(pstmt);
|
||||
// log.info(pstmt.getQueryString());
|
||||
// assertEquals(pstmt.getQueryString(), cql);
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.error("Failed to find method", e);
|
||||
}
|
||||
|
||||
CachedPreparedStatementCreator cpsc2 = new CachedPreparedStatementCreator(cql);
|
||||
|
||||
Book b2 = cassandraTemplate.query(cpsc2, new PreparedStatementBinder() {
|
||||
|
||||
@Override
|
||||
public BoundStatement bindValues(PreparedStatement ps) throws DriverException {
|
||||
return ps.bind("999999999");
|
||||
}
|
||||
}, new ResultSetExtractor<Book>() {
|
||||
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
Book b = new Book();
|
||||
b.setIsbn(r.getString("isbn"));
|
||||
b.setTitle(r.getString("title"));
|
||||
b.setAuthor(r.getString("author"));
|
||||
b.setPages(r.getInt("pages"));
|
||||
return b;
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(b2);
|
||||
|
||||
log.info(b2.toString());
|
||||
|
||||
}
|
||||
|
||||
@Cacheable("sdc-pstmts")
|
||||
public String echoString(String s) {
|
||||
log.info("In EchoString");
|
||||
return s;
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearCassandra() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
|
||||
Reference in New Issue
Block a user