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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.11.0 [unreleased]

### Bug Fixes
1. [#136](https://github.com/influxdata/influxdb-client-java/pull/136): Data Point: measurement name is requiring in constructor

## 1.10.0 [2020-07-17]

### Bug Fixes
Expand Down
17 changes: 13 additions & 4 deletions client/src/main/java/com/influxdb/client/write/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public final class Point {
private Number time;
private WritePrecision precision = DEFAULT_WRITE_PRECISION;

/**
* Create a new Point with specified a measurement name.
*
* @param measurementName the measurement name
*/
public Point(@Nonnull final String measurementName) {

Arguments.checkNotNull(measurementName, "measurement");

this.name = measurementName;
}

/**
* Create a new Point withe specified a measurement name.
*
Expand All @@ -83,10 +95,7 @@ public static Point measurement(@Nonnull final String measurementName) {

Arguments.checkNotNull(measurementName, "measurement");

Point point = new Point();
point.name = measurementName;

return point;
return new Point(measurementName);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion client/src/test/java/com/influxdb/client/write/PointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ void measurementEscape() {
Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2\\,o,location=europe level=2i");
}

@Test
public void createByConstructor() {
Point point = new Point("h2o")
.addTag("location", "europe")
.addField("level", 2);

Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe level=2i");
}

@SuppressWarnings("ConstantConditions")
@Test
public void createByConstructorMeasurementRequired() {
Assertions.assertThatThrownBy(() -> new Point(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Expecting a not null reference for measurement");
}

@Test
void tagEmptyKey() {

Expand Down Expand Up @@ -124,7 +141,7 @@ void fieldTypes() {
.addField("integer", 7)
.addField("integerObject", Integer.valueOf("8"))
.addField("boolean", false)
.addField("booleanObject", Boolean.parseBoolean("true"))
.addField("booleanObject", Boolean.TRUE)
.addField("string", "string value");

String expected = "h2o,location=europe bigDecimal=33.45,boolean=false,booleanObject=true,double=2.0,doubleObject=5.0,"
Expand Down