Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update actions/setup-java action to v3 #648

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-datastore/tre

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Native Image Datastore Sample | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java) |
| Quickstart Sample | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/QuickstartSample.java) |
| Task List | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import java.time.Instant;
import java.util.UUID;

/**
* Sample Datastore Application.
*/
/** Sample Datastore Application. */
public class NativeImageDatastoreSample {

/* Datastore namespace where entities will be created. */
Expand All @@ -39,9 +37,7 @@ public class NativeImageDatastoreSample {
/* Datastore kind used. */
private static final String TEST_KIND = "test-kind";

/**
* Entrypoint to the Datastore sample application.
*/
/** Entrypoint to the Datastore sample application. */
public static void main(String[] args) {
Instant startTime = Instant.now();
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Expand All @@ -64,9 +60,7 @@ public static void main(String[] args) {

static void addEntity(Datastore datastore, String id) {
Key key = createKey(datastore, id);
Entity entity = Entity.newBuilder(key)
.set("description", "hello world")
.build();
Entity entity = Entity.newBuilder(key).set("description", "hello world").build();
datastore.add(entity);
System.out.println("Successfully added entity.");
}
Expand All @@ -90,32 +84,35 @@ static void deleteEntity(Datastore datastore, String id) {
}

static void runTransactionCallable(Datastore datastore, Key entityKey) {
datastore.runInTransaction(client -> {
Entity entity = Entity.newBuilder(entityKey)
.set("description", "hello world")
.build();
datastore.add(entity);

StructuredQuery query =
Query.newEntityQueryBuilder()
.setNamespace(TEST_NAMESPACE)
.setKind(TEST_KIND)
.build();

QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
Entity result = results.next();
String name = result.getKey().getName();
String kind = result.getKey().getKind();
String namespace = result.getKey().getNamespace();
System.out.println(
"Found entity:" + "\n\t\tname=" + name + "\n\t\tkind=" + kind + "\n\t\tnamespace="
+ namespace + "\n\t\tproperties=" + result.getProperties().toString());
}

datastore.delete(entityKey);
return null;
});
datastore.runInTransaction(
client -> {
Entity entity = Entity.newBuilder(entityKey).set("description", "hello world").build();
datastore.add(entity);

StructuredQuery query =
Query.newEntityQueryBuilder().setNamespace(TEST_NAMESPACE).setKind(TEST_KIND).build();

QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
Entity result = results.next();
String name = result.getKey().getName();
String kind = result.getKey().getKind();
String namespace = result.getKey().getNamespace();
System.out.println(
"Found entity:"
+ "\n\t\tname="
+ name
+ "\n\t\tkind="
+ kind
+ "\n\t\tnamespace="
+ namespace
+ "\n\t\tproperties="
+ result.getProperties().toString());
}

datastore.delete(entityKey);
return null;
});

System.out.println("Ran transaction callable.");
}
Expand All @@ -129,9 +126,6 @@ private static void runTransaction(Datastore datastore) {
}

static Key createKey(Datastore datastore, String id) {
return datastore.newKeyFactory()
.setNamespace(TEST_NAMESPACE)
.setKind(TEST_KIND)
.newKey(id);
return datastore.newKeyFactory().setNamespace(TEST_NAMESPACE).setKind(TEST_KIND).newKey(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.junit.Before;
import org.junit.Test;

/**
* Tests for {@link com.example.datastore.NativeImageDatastoreSample}
*/
/** Tests for {@link com.example.datastore.NativeImageDatastoreSample} */
public class ITNativeImageDatastoreSample {

private Datastore datastore;
Expand All @@ -42,7 +40,6 @@ public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);

}

@Test
Expand All @@ -51,8 +48,7 @@ public void testAddAndGetEntity() {
String testId = "test-id-" + UUID.randomUUID();
NativeImageDatastoreSample.addEntity(datastore, testId);
NativeImageDatastoreSample.getEntity(datastore, testId);
assertThat(bout.toString()).contains(
"Reading entity: " + testId);
assertThat(bout.toString()).contains("Reading entity: " + testId);

NativeImageDatastoreSample.deleteEntity(datastore, testId);
}
Expand All @@ -63,13 +59,17 @@ public void testRunTransactionalCallable() {
String testId = "test-id-" + UUID.randomUUID();
Key key = NativeImageDatastoreSample.createKey(datastore, testId);
NativeImageDatastoreSample.runTransactionCallable(datastore, key);
assertThat(bout.toString()).contains(
"Found entity:" + "\n\t\tname=" + testId + "\n\t\tkind=test-kind"
+ "\n\t\tnamespace=nativeimage-test-namespace"
+ "\n\t\tproperties={description=StringValue{valueType=STRING, excludeFromIndexes=false,"
+ " meaning=0, value=hello world}}\n"
+ "Ran transaction callable.");
assertThat(bout.toString())
.contains(
"Found entity:"
+ "\n\t\tname="
+ testId
+ "\n\t\tkind=test-kind"
+ "\n\t\tnamespace=nativeimage-test-namespace"
+ "\n\t\tproperties={description=StringValue{valueType=STRING, excludeFromIndexes=false,"
+ " meaning=0, value=hello world}}\n"
+ "Ran transaction callable.");

NativeImageDatastoreSample.deleteEntity(datastore, "test-id");
}
}
}