Skip to content

Commit

Permalink
404: Style problems resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
oruam85 committed Jan 12, 2015
1 parent 496613f commit 19f2fe5
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 157 deletions.
171 changes: 88 additions & 83 deletions src/main/java/com/thindeck/dynamo/DyTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
import com.thindeck.api.Repo;
import com.thindeck.api.Task;
import com.thindeck.api.Tasks;

import java.io.IOException;
import java.util.Map;
import java.util.UUID;

import lombok.EqualsAndHashCode;
import lombok.ToString;

Expand All @@ -61,91 +59,98 @@
@ToString
@EqualsAndHashCode
public final class DyTasks implements Tasks {
/**
* Region we're in.
*/
private final transient Region region;
/**
* Repo we're in.
*/
private final transient Repo repo;
/**
* Region we're in.
*/
private final transient Region region;
/**
* Repo we're in.
*/
private final transient Repo repo;

/**
* Constructor.
*
* @param rgn
* Region
* @param rpo
* Repo
*/
public DyTasks(final Region rgn, final Repo rpo) {
this.region = rgn;
this.repo = rpo;
}
/**
* Constructor.
* @param rgn Region
* @param rpo Repo
*/
public DyTasks(final Region rgn, final Repo rpo) {
this.region = rgn;
this.repo = rpo;
}

@Override
public Task get(final long number) {
return new DyTask(this.region
.table(DyTask.TBL)
.frame()
.through(new QueryValve().withLimit(1))
.where(new Conditions().with(DyTask.ATTR_ID,
Conditions.equalTo(String.valueOf(number))).with(
DyTask.ATTR_REPO_URN,
Conditions.equalTo(this.repo.name()))).iterator()
.next());
}
@Override
public Task get(final long number) {
return new DyTask(
this.region.table(DyTask.TBL)
.frame()
.through(
new QueryValve().withLimit(1)
)
.where(
new Conditions().with(
DyTask.ATTR_ID,
Conditions.equalTo(String.valueOf(number))
).with(
DyTask.ATTR_REPO_URN,
Conditions.equalTo(this.repo.name())
)
).iterator().next()
);
}

@Override
public Iterable<Task> open() {
throw new UnsupportedOperationException("#open");
}
@Override
public Iterable<Task> open() {
throw new UnsupportedOperationException("#open");
}

@Override
public Iterable<Task> all() {
return Iterables
.transform(
this.region
.table(DyTask.TBL)
.frame()
.through(
new QueryValve()
.withConsistentRead(false)
.withSelect(
Select.ALL_PROJECTED_ATTRIBUTES)),
new Function<Item, Task>() {
@Override
public Task apply(final Item input) {
return new DyTask(input);
}
});
}
@Override
public Iterable<Task> all() {
return Iterables.transform(
this.region.table(DyTask.TBL)
.frame()
.through(
new QueryValve().withConsistentRead(false)
.withSelect(Select.ALL_PROJECTED_ATTRIBUTES)
),
new Function<Item, Task>() {
@Override
public Task apply(final Item input) {
return new DyTask(input);
}
}
);
}

@Override
public Task add(final String command, final Map<String, String> args) {
try {
return new DyTask(this.region.table(DyTask.TBL).put(
new Attributes().with(DyTask.ATTR_ID, UUID.randomUUID())
.with(DyTask.ATTR_REPO_URN, this.repo.name())
.with(DyTask.ATTR_COMM, command)
.with(this.toAttributes(args))));
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
}
@Override
public Task add(final String command, final Map<String, String> args) {
try {
return new DyTask(
this.region.table(DyTask.TBL)
.put(new Attributes()
.with(DyTask.ATTR_ID, UUID.randomUUID())
.with(
DyTask.ATTR_REPO_URN,
this.repo.name()
)
.with(DyTask.ATTR_COMM, command)
.with(this.toAttributes(args))
)
);
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
}

/**
* Map to {@link com.jcabi.dynamo.Attributes}.
*
* @param map
* Map
* @return Attributes
*/
private Attributes toAttributes(final Map<String, String> map) {
final Attributes attributes = new Attributes();
for (final Map.Entry<String, String> entry : map.entrySet()) {
attributes.with(entry.getKey(), entry.getValue());
}
return attributes;
}
/**
* Map to {@link com.jcabi.dynamo.Attributes}.
* @param map Map
* @return Attributes
*/
private Attributes toAttributes(final Map<String, String> map) {
final Attributes attributes = new Attributes();
for (final Map.Entry<String, String> entry : map.entrySet()) {
attributes.with(entry.getKey(), entry.getValue());
}
return attributes;
}
}
150 changes: 76 additions & 74 deletions src/test/java/com/thindeck/dynamo/DyTasksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@
import com.thindeck.api.Repo;
import com.thindeck.api.Task;
import com.thindeck.api.mock.MkRepo;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import java.util.concurrent.ConcurrentHashMap;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
Expand All @@ -57,6 +53,11 @@
*/
public final class DyTasksTest {

/**
* The custom command.
*/
private static final transient String CMD = "command";

/**
* DyTasks can retrieve Task by number.
* @throws Exception In case of error.
Expand All @@ -73,107 +74,108 @@ public void getTask() throws Exception {
Matchers.equalTo(tid)
);
}

/**
* DyTask can add a task with attributes in NULL
* @throws Exception In case of error
* DyTask can add a task with attributes in NULL.
* @throws Exception In case of error.
*/
@Test
@Ignore
public void addTaskNullAttributes() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final String command = "command";
DyTasks tasks = new DyTasks(region, repo);
Task task = tasks.add(command,null);
MatcherAssert.assertThat(task.command(),Matchers.equalTo(command));
public void addTaskNullAttributes() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final DyTasks tasks = new DyTasks(region, repo);
final Task task = tasks.add(DyTasksTest.CMD, null);
MatcherAssert.assertThat(
task.command(),
Matchers.equalTo(DyTasksTest.CMD)
);
}

/**
* DyTask can add a task without attributes.
* @throws Exception In case of error
* @throws Exception In case of error.
*/
@Test
@Ignore
public void addTaskWithoutAttributes() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final String command = "command";
DyTasks tasks = new DyTasks(region, repo);
Map <String,String> map = new HashMap<String,String>();
Task task = tasks.add(command,map);

MatcherAssert.assertThat(task.command(),Matchers.equalTo(command));
public void addTaskWithoutAttributes() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final DyTasks tasks = new DyTasks(region, repo);
final ConcurrentHashMap<String, String> map =
new ConcurrentHashMap<String, String>();
final Task task = tasks.add(DyTasksTest.CMD, map);
MatcherAssert.assertThat(
task.command(),
Matchers.equalTo(DyTasksTest.CMD)
);
}

/**
* DyTask can add a task with attributes.
* @throws Exception In case of error
* @throws Exception In case of error.
*/
@Test
@Ignore
public void addTaskWithAttributes() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final String command = "command";

DyTasks tasks = new DyTasks(region, repo);
Map <String,String> map = new HashMap<String,String>();
map.put("key", "value");
Task task = tasks.add(command,map);

MatcherAssert.assertThat(task.command(),Matchers.equalTo(command));
public void addTaskWithAttributes() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final DyTasks tasks = new DyTasks(region, repo);
final ConcurrentHashMap<String, String> map =
new ConcurrentHashMap<String, String>();
map.put("key", "value");
final Task task = tasks.add(DyTasksTest.CMD, map);
MatcherAssert.assertThat(
task.command(),
Matchers.equalTo(DyTasksTest.CMD)
);
}

/**
* DyTasks can get all task empty
* @throws Exception In case of error
* DyTasks can get all task empty.
* @throws Exception In case of error.
*/
@Test
public void allWithoutTask() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());

DyTasks tasks = new DyTasks(region, repo);

MatcherAssert.assertThat(tasks.all(),Matchers.emptyIterable());
public void allWithoutTask() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name());
final DyTasks tasks = new DyTasks(region, repo);
MatcherAssert.assertThat(tasks.all(), Matchers.emptyIterable());
}

/**
* DyTasks can get the only one task
* @throws Exception In case of error
* DyTasks can get the only one task.
* @throws Exception In case of error.
*/
@Test
public void allWithOneTask() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name(),10L);

DyTasks tasks = new DyTasks(region, repo);

MatcherAssert.assertThat(tasks.all(),Matchers.<Task>iterableWithSize(1));
public void allWithOneTask() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name(), 10L);
final DyTasks tasks = new DyTasks(region, repo);
MatcherAssert.assertThat(
tasks.all(),
Matchers.<Task>iterableWithSize(1)
);
}

/**
* DyTasks can get the all the tasks
* @throws Exception In case of error
* DyTasks can get the all the tasks.
* @throws Exception In case of error.
*/
@Test
public void allWithMoreThatOneTask() throws Exception{
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name(),10L,20L);

DyTasks tasks = new DyTasks(region, repo);

MatcherAssert.assertThat(tasks.all(),Matchers.<Task>iterableWithSize(2));
public void allWithMoreThatOneTask() throws Exception {
final Repo repo = new MkRepo();
final Region region = DyTasksTest.region(repo.name(), 10L, 20L);
final DyTasks tasks = new DyTasks(region, repo);
MatcherAssert.assertThat(
tasks.all(),
Matchers.<Task>iterableWithSize(2)
);
}

/**
* Create region with one repo and multiple tasks.
* @param repo Repo urn
* @param repo Repo urn.
* @param ids Ids of tasks.
* @return Region created.
* @throws IOException In case of error.
Expand Down

0 comments on commit 19f2fe5

Please sign in to comment.