Skip to content

Commit

Permalink
I was able to create a new test for that and i also corrected the def…
Browse files Browse the repository at this point in the history
…ect. The test makes sure that a given statement object doesn't send twice the same query.

I had to mock the MondrianInprocProxy class and create a hash map of the requests that go through it. If the same request is sent twice, an exception gets triggered. The only exception to this is the MDSCHEMA_CUBES query that is used to populate both the catalogs and the schemas associated to a given catalog. This was due to a flaw in SSAS; it doesn't return a SCHEMA_NAME column when asked to. We fixed it this way in some other revision.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@127 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Nov 3, 2008
1 parent dfcb158 commit 0919416
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,17 @@ public void lookupMembersByUniqueName(
// by delegating.
if (!remainingMemberUniqueNames.isEmpty()) {
super.lookupMembersByUniqueName(
memberUniqueNames,
remainingMemberUniqueNames,
memberMap);
// Add the previously missing members into the cache.
for (String memberName : remainingMemberUniqueNames) {
XmlaOlap4jMember member = memberMap.get(memberName);
if (member != null) {
this.memberMap.put(
memberName,
new SoftReference<XmlaOlap4jMember>(member));
}
}
}
}

Expand Down
110 changes: 108 additions & 2 deletions testsrc/org/olap4j/XmlaConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

import java.io.IOException;
import java.net.URL;
import java.sql.DriverManager;
import java.util.Properties;
import java.security.*;
import java.sql.*;
import java.util.*;
import java.util.concurrent.Future;

import mondrian.olap4j.MondrianInprocProxy;

import org.olap4j.driver.xmla.XmlaOlap4jDriver;
import org.olap4j.driver.xmla.proxy.XmlaOlap4jProxy;
import org.olap4j.test.TestContext;

import junit.framework.TestCase;

public class XmlaConnectionTest extends TestCase {

public static final String DRIVER_CLASS_NAME =
"org.olap4j.driver.xmla.XmlaOlap4jDriver";
private TestContext.Tester tester = null;

static class XmlaOlap4jProxyMock implements XmlaOlap4jProxy {
public byte[] get(URL url, String request) throws IOException {
Expand All @@ -29,6 +34,34 @@ public Future<byte[]> submit(URL url, String request) {
throw new RuntimeException("Non-Trivial Call!");
}
}
public static class DoubleSubmissionTestProxy extends MondrianInprocProxy {
Map<String,String> requests = new HashMap<String,String>();
public DoubleSubmissionTestProxy(
Map<String, String> catalogNameUrls,
String urlString)
{
super(catalogNameUrls,urlString);
}
@Override
public byte[] get(URL url, String request) throws IOException {
this.checkup(request);
return super.get(url, request);
}
// @Override
// public Future<byte[]> submit(URL url, String request) {
// this.checkup(request);
// return super.submit(url, request);
// }
private void checkup(String request) {
String hash = Encoder.convertToHex(request.getBytes());
if ( request.indexOf("<RequestType>MDSCHEMA_CUBES</RequestType>") == -1 &&
this.requests.containsKey(hash)) {
throw new RuntimeException("DOUBLE-REQUEST");
} else {
this.requests.put(hash,request);
}
}
}

/**
* this test verifies that the construction of the necessary
Expand Down Expand Up @@ -57,6 +90,79 @@ public void testNoNonTrivalCallsOnConnect() throws Exception {
fail("Non-Trival Call executed during construction of XmlaOlap4j Connection");
}
}

public void testNoDoubleQuerySubmission() throws Exception {
String oldValue = XmlaTester.getProxyClassName();
XmlaTester.setProxyClassName(
DoubleSubmissionTestProxy.class.getName());
if ( TestContext.getTestProperties()
.get(TestContext.Property.HELPER_CLASS_NAME.path)
.equals("org.olap4j.XmlaTester"))
{
try {
tester = TestContext.instance().getTester();
Connection connection = tester.createConnection();
Statement statement = connection.createStatement();
final OlapStatement olapStatement =
tester.getWrapper().unwrap(statement, OlapStatement.class);
@SuppressWarnings("unused")
CellSet cellSet =
olapStatement.executeOlapQuery(
"SELECT\n" +
" {[Measures].[Unit Sales],\n" +
" [Measures].[Store Sales]} ON COLUMNS\n," +
" Crossjoin({[Gender].[M]}, [Product].Children) ON ROWS\n" +
"FROM [Sales]\n" +
"WHERE [Time].[1997].[Q2]");
cellSet =
olapStatement.executeOlapQuery(
"SELECT\n" +
" {[Measures].[Unit Sales],\n" +
" [Measures].[Store Sales]} ON COLUMNS\n," +
" Crossjoin({[Gender].[M]}, [Product].Children) ON ROWS\n" +
"FROM [Sales]\n" +
"WHERE [Time].[1997].[Q3]");
} catch(RuntimeException e) {
fail(e.getMessage());
}
}
XmlaTester.setProxyClassName(oldValue);
}

private static class Encoder {
private static String convertToHex(byte[] data) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9)) {
buf.append((char) ('0' + halfbyte));
} else {
buf.append((char) ('a' + (halfbyte - 10)));
}
halfbyte = data[i] & 0x0F;
} while (two_halfs++ < 1);
}
return buf.toString();
}
public static String SHA1(String text) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e1) {
throw new RuntimeException(e1);
}
}
byte[] sha1hash = new byte[40];
md.update(text.getBytes(), 0, text.length());
sha1hash = md.digest();
return convertToHex(sha1hash);
}
}
}

// End XmlaConnectionTest.java
11 changes: 10 additions & 1 deletion testsrc/org/olap4j/XmlaTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public XmlaTester()
String urlString =
properties.getProperty(TestContext.Property.CONNECT_URL.path);

final Class<?> clazz = Class.forName("mondrian.olap4j.MondrianInprocProxy");
final Class<?> clazz = Class.forName(getProxyClassName());
final Constructor<?> constructor =
clazz.getConstructor(Map.class, String.class);
this.proxy =
Expand Down Expand Up @@ -115,12 +115,21 @@ public TestContext.Wrapper getWrapper() {
return TestContext.Wrapper.NONE;
}

public static void setProxyClassName(String clazz) {
PROXY_CLASS_NAME = clazz;
}

public static String getProxyClassName() {
return PROXY_CLASS_NAME;
}

public static final String DRIVER_CLASS_NAME =
"org.olap4j.driver.xmla.XmlaOlap4jDriver";

public static final String DRIVER_URL_PREFIX = "jdbc:xmla:";
private static final String USER = "user";
private static final String PASSWORD = "password";
private static String PROXY_CLASS_NAME = "mondrian.olap4j.MondrianInprocProxy";
}

// End XmlaTester.java

0 comments on commit 0919416

Please sign in to comment.