Skip to content

Commit 323c2ff

Browse files
authored
#1654 Fix bug when deleting unused key (#1655)
* 1654 Polish * #1654 Deleting key not present in table * #1654 Deleting key not present in table * #1654 Deleting key not present in table * #1654 Deleting key not present in table * #1654 Deleting key not present in table * #1654 Deleting key not present in table * #1654 Deleting key not present in table
1 parent 69e00a5 commit 323c2ff

File tree

4 files changed

+74
-31
lines changed

4 files changed

+74
-31
lines changed

example/virtualized-table/pom.xml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,6 @@
275275
</execution>
276276
</executions>
277277
</plugin>
278-
<plugin>
279-
<groupId>org.apache.maven.plugins</groupId>
280-
<artifactId>maven-javadoc-plugin</artifactId>
281-
<executions>
282-
<execution>
283-
<id>attach-javadocs</id>
284-
<goals><goal>jar</goal></goals>
285-
</execution>
286-
</executions>
287-
</plugin>
288-
<plugin>
289-
<groupId>org.apache.maven.plugins</groupId>
290-
<artifactId>maven-source-plugin</artifactId>
291-
<executions>
292-
<execution>
293-
<phase>compile</phase>
294-
<goals><goal>jar</goal></goals>
295-
</execution>
296-
</executions>
297-
</plugin>
298-
299278
</plugins>
300279
</build>
301280
<reporting>

vuu/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@
171171
<artifactId>awaitility-scala</artifactId>
172172
<version>4.3.0</version>
173173
<scope>test</scope>
174+
<exclusions>
175+
<exclusion>
176+
<groupId>org.scala-lang</groupId>
177+
<artifactId>scala-library</artifactId>
178+
</exclusion>
179+
</exclusions>
174180
</dependency>
175181

176182
</dependencies>

vuu/src/main/scala/org/finos/vuu/core/table/InMemDataTable.scala

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.finos.vuu.core.table
22

3+
import com.typesafe.scalalogging.StrictLogging
34
import org.finos.vuu.api.TableDef
45
import org.finos.vuu.core.index._
56
import org.finos.vuu.provider.{JoinTableProvider, Provider}
@@ -219,7 +220,7 @@ case class InMemDataTableData(data: ConcurrentHashMap[String, RowData], private
219220
}
220221

221222

222-
class InMemDataTable(val tableDef: TableDef, val joinProvider: JoinTableProvider)(implicit val metrics: MetricsProvider) extends DataTable with KeyedObservableHelper[RowKeyUpdate] {
223+
class InMemDataTable(val tableDef: TableDef, val joinProvider: JoinTableProvider)(implicit val metrics: MetricsProvider) extends DataTable with KeyedObservableHelper[RowKeyUpdate] with StrictLogging {
223224

224225
private final val indices = tableDef.indices.indices
225226
.map(index => tableDef.columnForName(index.column))
@@ -392,12 +393,15 @@ class InMemDataTable(val tableDef: TableDef, val joinProvider: JoinTableProvider
392393
updateIndices(rowkey, rowUpdate)
393394
}
394395

395-
def delete(rowKey: String): Unit = {
396+
def delete(rowKey: String): RowData = {
396397
data.dataByKey(rowKey) match {
397-
case EmptyRowData =>
398398
case x: RowWithData =>
399399
removeFromIndices(rowKey, x)
400400
data = data.delete(rowKey)
401+
x
402+
case _ =>
403+
logger.debug(s"Got a delete for key $rowKey, but it has no row data")
404+
EmptyRowData
401405
}
402406
}
403407

@@ -479,14 +483,15 @@ class InMemDataTable(val tableDef: TableDef, val joinProvider: JoinTableProvider
479483

480484
onUpdateCounter.inc()
481485

482-
val rowData = data.dataByKey(rowKey)
483-
484-
delete(rowKey)
486+
val rowData = delete(rowKey)
485487

486-
if (rowData != null)
487-
sendDeleteToJoinSink(rowKey, rowData)
488+
rowData match {
489+
case RowWithData(_, _) =>
490+
sendDeleteToJoinSink(rowKey, rowData)
491+
notifyListeners(rowKey, isDelete = true)
488492

489-
notifyListeners(rowKey, isDelete = true)
493+
case EmptyRowData =>
494+
}
490495

491496
incrementUpdateCounter()
492497
}

vuu/src/test/scala/org/finos/vuu/core/table/RowDeleteTest.scala

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,67 @@ class RowDeleteTest extends AnyFeatureSpec with Matchers with OneInstancePerTest
8282
assertVpEq(updates2) {
8383
Table(
8484
("ric" ,"bid" ,"ask" ),
85-
//("VOD.L" ,220 ,223 ),
8685
("BT.L" ,220 ,223 ),
8786
("TW.L" ,220 ,223 )
8887
)
8988
}
9089

9190
}
9291

92+
Scenario("check a delete of a key that doesn't exist does nothing"){
93+
implicit val clock: Clock = new DefaultClock
94+
95+
implicit val lifecycle: LifecycleContainer = new LifecycleContainer
96+
implicit val metrics: MetricsProviderImpl = new MetricsProviderImpl
97+
98+
val joinProvider = JoinTableProviderImpl()
99+
100+
val tableContainer = new TableContainer(joinProvider)
101+
102+
val outQueue = new OutboundRowPublishQueue()
103+
104+
val providerContainer = new ProviderContainer(joinProvider)
105+
val pluginRegistry = new DefaultPluginRegistry
106+
pluginRegistry.registerPlugin(new VuuInMemPlugin)
107+
108+
val viewPortContainer = new ViewPortContainer(tableContainer, providerContainer, pluginRegistry)
109+
110+
val pricesDef = TableDef("prices", "ric", Columns.fromNames("ric:String", "bid:Double", "ask:Double", "last:Double", "open:Double", "close:Double"), "ric")
111+
112+
val table = new InMemDataTable(pricesDef, joinProvider)
113+
114+
val provider = new MockProvider(table)
115+
116+
val session = ClientSessionId("sess-01", "chris")
117+
118+
val vpcolumns = ViewPortColumnCreator.create(table, List("ric", "bid", "ask"))
119+
120+
val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, table, DefaultRange, vpcolumns)
121+
122+
provider.tick("VOD.L", Map("ric" -> "VOD.L", "bid" -> 220, "ask" -> 223))
123+
124+
table.primaryKeys.length should equal (1)
125+
126+
viewPortContainer.runOnce()
127+
128+
val updates = combineQs(viewPort)
129+
130+
assertVpEq(updates) {
131+
Table(
132+
("ric", "bid", "ask"),
133+
("VOD.L", 220, 223)
134+
)
135+
}
136+
137+
provider.delete("TW.L")
138+
139+
viewPortContainer.runOnce()
140+
141+
val updates2 = combineQs(viewPort)
142+
143+
assert(updates2.isEmpty)
144+
}
145+
93146
Scenario("check we correct delete from a primary key join table"){
94147

95148
implicit val clock: Clock = new TestFriendlyClock(1000000)

0 commit comments

Comments
 (0)