Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Adds test case for StreakYC#12 and properly fix it.
Browse files Browse the repository at this point in the history
Fixes misuse of query predicates on previous commit of
BuiltinDatastoreToBigqueryIngesterTask, that was causing it to fail
backwards.

Also adds a new test case to the test suite so this can be
verified as fixed.
  • Loading branch information
ronoaldo committed Jun 18, 2013
1 parent 4c0cf59 commit 688eea9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,21 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
}


private String checkAndGetCompletedBackup(String backupName) throws IOException {
String checkAndGetCompletedBackup(String backupName) throws IOException {
System.err.println("backupName: " + backupName);

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Expand All @@ -210,8 +210,11 @@ private String checkAndGetCompletedBackup(String backupName) throws IOException

// for some reason the datastore admin code appends the date to the backup name even when creating programatically,
// so test for greater than or equal to and then take the first result
q.setFilter(new FilterPredicate("name", FilterOperator.GREATER_THAN_OR_EQUAL, backupName));
q.setFilter(new FilterPredicate("name", FilterOperator.LESS_THAN, backupName + Character.MAX_VALUE));
Query.Filter greatherThanOrEqual = new FilterPredicate("name",
FilterOperator.GREATER_THAN_OR_EQUAL, backupName);
Query.Filter lessThan = new FilterPredicate("name", FilterOperator.LESS_THAN,
backupName + Character.MAX_VALUE);
q.setFilter(Query.CompositeFilterOperator.and(greatherThanOrEqual, lessThan));

PreparedQuery pq = datastore.prepare(q);
List<Entity> results = pq.asList(FetchOptions.Builder.withLimit(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.streak.datastore.analysis.builtin;

import static com.google.appengine.api.datastore.KeyFactory.*;
import static org.junit.Assert.*;

import java.util.*;
import java.util.logging.*;
import com.google.appengine.api.datastore.*;

import org.junit.*;
import com.google.appengine.tools.development.testing.*;

public class BuiltinDatastoreToBigqueryIngesterTaskTest {

private static final Logger LOG = Logger.getLogger( //
BuiltinDatastoreToBigqueryIngesterTaskTest.class.getName());

private DatastoreService ds;

private LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());

private static Integer operation = 1;

@Before
public void setUpDatastore() {
helper.setUp();
ds = DatastoreServiceFactory.getDatastoreService();
}

@After
public void tearDownDatastore() {
helper.tearDown();
}

@Test
public void testCheckAndGetCompletedBackup() throws Exception {
long ts = System.currentTimeMillis();
String targetName = "current_backup" + ts;

fixtureForBackup("a_previous_backup", new Date());
fixtureForBackup(targetName, null);
fixtureForBackup("z_latest_backup" + ts, new Date());

BuiltinDatastoreToBigqueryIngesterTask task = new BuiltinDatastoreToBigqueryIngesterTask();
assertNull(task.checkAndGetCompletedBackup(targetName));
}

private synchronized Entity fixtureForBackup(String name, Date completeTime) {
Key ancestor = createKey("_AE_DatastoreAdmin_Operation", ++operation);
Entity e = new Entity(createKey(ancestor, "_AE_Backup_Information", ++operation));
e.setProperty("name", name);
e.setProperty("complete_time", completeTime);

ds.put(e);
LOG.info("Added fixture for " + e.toString());
return e;
}
}

0 comments on commit 688eea9

Please sign in to comment.