Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,4 @@ public void mustGetPossiblyMissingAttributeByClass() {
assertEquals(
Optional.of(new Attributes.Name("b")), attributes.getAttribute(Attributes.Name.class));
}

@Deprecated
@Test
public void mustGetPossiblyMissingFirstAttributeByClass() {
assertEquals(
Optional.of(new Attributes.Name("a")), attributes.getFirstAttribute(Attributes.Name.class));
}

@Deprecated
@Test
public void mustGetMissingFirstAttributeByClass() {
assertEquals(Optional.empty(), attributes.getFirstAttribute(Attributes.LogLevels.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ class AttributesSpec

val attributes = Attributes.name("a") and Attributes.name("b") and Attributes.inputBuffer(1, 2)

"give access to the least specific attribute" in {
val name = attributes.getFirst[Name]
name should ===(Some(Attributes.Name("a")))
}

"give access to the most specific attribute value" in {
val name = attributes.get[Name]
name should ===(Some(Attributes.Name("b")))
Expand Down Expand Up @@ -217,7 +212,7 @@ class AttributesSpec
name shouldBe Some(Name("new-name"))
}

"keep the outermost attribute as the least specific" in {
"keep the stage attribute as the most specific" in {
val attributes = Source
.fromGraph(new AttributesSource(Attributes.name("original-name")))
.map(identity)
Expand All @@ -227,9 +222,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("original-name"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("whole-graph"))
}
}

Expand All @@ -245,9 +237,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("new-name"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("new-name"))
}

"make the attributes on Source.fromGraph source behave the same as the stage itself" in {
Expand All @@ -263,11 +252,6 @@ class AttributesSpec
mostSpecificName shouldBe Some(Name("replaced"))
val mostSpecificWhatever = attributes.get[WhateverAttribute]
mostSpecificWhatever shouldBe None

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("whole-graph"))
val leastSpecificWhatever = attributes.getFirst[WhateverAttribute]
leastSpecificWhatever shouldBe None
}

"not replace stage specific attributes with attributes on surrounding composite source" in {
Expand All @@ -281,9 +265,6 @@ class AttributesSpec
// still the original as the attribute was added on the composite source
val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("original-name"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("composite-graph"))
}

"make the attributes on Sink.fromGraph source behave the same as the stage itself" in {
Expand All @@ -299,9 +280,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("replaced"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("whole-graph"))
}

"use the initial attributes for dispatcher" in {
Expand Down Expand Up @@ -414,8 +392,6 @@ class AttributesSpec

val name = attributes.get[Name]
name shouldBe Some(Name("replaced"))
val firstName = attributes.getFirst[Name]
firstName shouldBe Some(Name("whole-graph"))
}

"handle attributes on a composed flow" in {
Expand All @@ -438,11 +414,6 @@ class AttributesSpec
name shouldBe Some(Name("original-name"))
val whatever = attributes.get[WhateverAttribute]
whatever shouldBe Some(WhateverAttribute("replaced"))

val firstName = attributes.getFirst[Name]
firstName shouldBe Some(Name("replaced-again"))
val firstWhatever = attributes.getFirst[WhateverAttribute]
firstWhatever shouldBe Some(WhateverAttribute("replaced"))
}

"get input buffer size from surrounding .addAttributes (closest)" in {
Expand Down Expand Up @@ -572,9 +543,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("replaced"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("whole-graph"))
}

}
Expand Down Expand Up @@ -621,9 +589,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName shouldBe Some(Name("replaced"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName shouldBe Some(Name("whole-graph"))
}

"make the attributes on Flow.fromGraph source behave the same as the stage itself" in {
Expand All @@ -643,9 +608,6 @@ class AttributesSpec

val mostSpecificName = attributes.get[Name]
mostSpecificName should contain(Name("replaced"))

val leastSpecificName = attributes.getFirst[Name]
leastSpecificName should contain(Name("whole-graph"))
}

"make the attributes on Sink.fromGraph source behave the same as the stage itself" in {
Expand All @@ -664,10 +626,6 @@ class AttributesSpec
// most specific
val mostSpecificName = attributes.get[Name]
mostSpecificName should contain(Name("replaced"))

// least specific
val leastSpecificName = attributes.getFirst[Name]
leastSpecificName should contain(Name("whole-graph"))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class BidiFlowSpec extends StreamSpec {
import Attributes._
val b: BidiFlow[Int, Long, ByteString, String, NotUsed] = bidi.async.addAttributes(none).named("name")

val name = b.traversalBuilder.attributes.getFirst[Name]
val name = b.traversalBuilder.attributes.get[Name]
name shouldEqual Some(Name("name"))
val boundary = b.traversalBuilder.attributes.getFirst[AsyncBoundary.type]
val boundary = b.traversalBuilder.attributes.get[AsyncBoundary.type]
boundary shouldEqual Some(AsyncBoundary)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ class GraphDSLCompileSpec extends StreamSpec {
.addAttributes(none)
.named("useless")

val name = ga.traversalBuilder.attributes.getFirst[Name]
val name = ga.traversalBuilder.attributes.get[Name]
name shouldEqual Some(Name("useless"))
val boundary = ga.traversalBuilder.attributes.getFirst[AsyncBoundary.type]
val boundary = ga.traversalBuilder.attributes.get[AsyncBoundary.type]
boundary shouldEqual (Some(AsyncBoundary))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ class SinkSpec extends StreamSpec with DefaultTimeout with ScalaFutures {
val s: Sink[Int, Future[Int]] = Sink.head[Int].async.addAttributes(none).named("name")

s.traversalBuilder.attributes.filtered[Name] shouldEqual List(Name("name"), Name("headSink"))
@nowarn("msg=deprecated")
val res = s.traversalBuilder.attributes.getFirst[Attributes.AsyncBoundary.type]
val res = s.traversalBuilder.attributes.get[Attributes.AsyncBoundary.type]
res shouldEqual (Some(AsyncBoundary))
}

Expand All @@ -255,30 +254,13 @@ class SinkSpec extends StreamSpec with DefaultTimeout with ScalaFutures {
s.traversalBuilder.attributes.get[Name](Name("default")) shouldEqual Name("name")
}

"given no attributes of a class when getting first attribute with default value should get default value" in {
import Attributes._
val s: Sink[Int, Future[Int]] = Sink.head[Int].withAttributes(none).async

@nowarn("msg=deprecated")
val res = s.traversalBuilder.attributes.getFirst[Name](Name("default"))
res shouldEqual Name("default")
}

"given no attributes of a class when getting last attribute with default value should get default value" in {
import Attributes._
val s: Sink[Int, Future[Int]] = Sink.head[Int].withAttributes(none).async

s.traversalBuilder.attributes.get[Name](Name("default")) shouldEqual Name("default")
}

"given multiple attributes of a class when getting first attribute with default value should get first attribute" in {
import Attributes._
val s: Sink[Int, Future[Int]] = Sink.head[Int].withAttributes(none).async.named("name").named("another_name")
@nowarn("msg=deprecated")
val res = s.traversalBuilder.attributes.getFirst[Name](Name("default"))
res shouldEqual Name("name")
}

"given multiple attributes of a class when getting last attribute with default value should get last attribute" in {
import Attributes._
val s: Sink[Int, Future[Int]] = Sink.head[Int].async.addAttributes(none).named("name").named("another_name")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Remove deprecated Attributes.getFirst/getFirstAttribute (deprecated since Akka 2.5.7)
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirstAttribute")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirst")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Remove deprecated Attributes.getFirst/getFirstAttribute (deprecated since Akka 2.5.7)
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirstAttribute")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirst")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Remove deprecated Attributes.getFirst/getFirstAttribute (deprecated since Akka 2.5.7)
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirstAttribute")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.stream.Attributes.getFirst")
36 changes: 0 additions & 36 deletions stream/src/main/scala/org/apache/pekko/stream/Attributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -302,42 +302,6 @@ final class Attributes private[pekko] (
attributeList.collect { case attr if c.isAssignableFrom(attr.getClass) => c.cast(attr) }
}

/**
* Java API: Get the least specific attribute (added first) of a given `Class` or subclass thereof.
* If no such attribute exists the `default` value is returned.
*/
@deprecated("Attributes should always be most specific, use getAttribute[T]", "Akka 2.5.7")
def getFirstAttribute[T <: Attribute](c: Class[T], default: T): T =
getFirstAttribute(c).orElse(default)

/**
* Java API: Get the least specific attribute (added first) of a given `Class` or subclass thereof.
*/
@deprecated("Attributes should always be most specific, use get[T]", "Akka 2.5.7")
def getFirstAttribute[T <: Attribute](c: Class[T]): Optional[T] =
attributeList.reverseIterator.collectFirst { case attr if c.isInstance(attr) => c.cast(attr) }.toJava

/**
* Scala API: Get the least specific attribute (added first) of a given type parameter T `Class` or subclass thereof.
* If no such attribute exists the `default` value is returned.
*/
@deprecated("Attributes should always be most specific, use get[T]", "Akka 2.5.7")
def getFirst[T <: Attribute: ClassTag](default: T): T = {
getFirst[T] match {
case Some(a) => a
case None => default
}
}

/**
* Scala API: Get the least specific attribute (added first) of a given type parameter T `Class` or subclass thereof.
*/
@deprecated("Attributes should always be most specific, use get[T]", "Akka 2.5.7")
def getFirst[T <: Attribute: ClassTag]: Option[T] = {
val c = classTag[T].runtimeClass.asInstanceOf[Class[T]]
attributeList.reverseIterator.collectFirst { case attr if c.isInstance(attr) => c.cast(attr) }
}

// for binary compatibility (used to be a case class)

@deprecated("Use explicit methods on Attributes to interact, not the ones provided by Product", "2.0.0")
Expand Down